2013年11月11日 星期一

Perl read / write Excel file

Reference:
http://blog.dwightmann.com/entry.asp?id=60
http://stackoverflow.com/questions/9761443/issues-reading-time-value-in-perl-using-win32ole

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3; # die on errors...

$excel_file = "c:/tmp/myexcel.xls";

my $Excel_to_read = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $Book_to_read = $Excel_to_read->Workbooks->Open($excel_file);
my $Sheet_to_read = $Book_to_read->Worksheets(1);

print $Sheet_to_read->Cells(5,3)->{'Value'};

註:針對欄位格式為自訂,必須用$Sheet_to_read->Cells(5,3)->{'Text'}

2013年11月4日 星期一

DELL R620 install network card driver on CentOS 5.6

Reference:
http://public.support.unisys.com/pcproducts/esx/docs/delldocs5.4/en/broadcom/netxtreme/linux.htm
ftp://ftp.dell.com/Pages/Drivers/poweredge-r620-all.html#Network


DELL driver download 網站有好幾款網路卡driver,把 DELL R620 打開看到網路卡寫 BRCM GbE 4P 5720-t rNDC,用 Google 搜尋後確認是 Broadcom 網路卡。

在 DELL 網站 download Broadcom network driver。
用 rpm -ivh 安裝時出現需要 DKMS。
搜尋 DELL DKMS 後 download DKMS from http://linux.dell.com/dkms/
用 rpm -ivh dkms-version.src.rpm 安裝
再安裝 rpm -ivh tg3-3.124c-1.dkms.noarch.rpm

Perl CPAN urllist reconfig

Reference:
http://major.io/2008/06/16/adjusting-cpan-mirror-list/

執行 cpan
Display your current mirrors:
cpan> o conf urllist

Delete the first mirror in your list:
cpan> o conf urllist shift

Delete the last mirror in your list:
cpan>  o conf urllist pop

Reconfig:
cpan> o conf init

2013年11月2日 星期六

[轉錄]PTT上ungm板友的簽名檔-帥哥醜男跟阿宅的比較



   行為
人種
在家
微笑
留鬚
搭訕
看書
搭肩
運動
睡著
耍溫柔
裝豪邁
*帥哥*
孝順
陽光
有型
開心
斯文
害羞
活力
可愛
體貼
男人味
醜男
無聊
變態
拉褟
報警
蠢
騷擾
減肥
懶惰
娘娘腔
粗漢
宅男
宅
宅
宅
宅
宅
宅
宅
宅
宅
宅

2013年11月1日 星期五

Perl send mail via gmail

Reference:
http://dipinkrishna.com/blog/2010/12/sending-emails-gmail-smtp-perl/

use Net::SMTP::TLS;   # ActivePerl 5.14 才有

my $smtp = new Net::SMTP::TLS(
'smtp.gmail.com',
Port    => 587,
User    => 'sender@gmail.com',
Password=> 'Password',
Timeout => 30
);

#  -- Enter email FROM below.   --
$smtp->mail('sender@gmail.com');

#  -- Enter recipient mails addresses below --
my @recipients = ('recipient1@gmail.com', 'recipient2@yahoo.com');
$smtp->recipient(@recipients);
$smtp->bcc(@recipients);

$smtp->data();

#This part creates the SMTP headers you see
$smtp->datasend("To: recipient1\@gmail.com\n");
$smtp->datasend("From: Chandler \n");
$smtp->datasend("Content-Type: text/html \n");
$smtp->datasend("Subject: A Test Mail");
# line break to separate headers from message body
$smtp->datasend("\n");
$smtp->datasend("This is a test mail body");
$smtp->datasend("\n");
$smtp->dataend();

$smtp->quit;

Perl web file download

Reference:
http://jck11.pixnet.net/blog/post/4899927-%E5%88%A9%E7%94%A8lwp%3A%3Asimple%E4%B8%8B%E8%BC%89%E7%B6%B2%E9%A0%81%5Bperl%5D

use LWP::Simple;

my $url = "http://www.otc.org.tw/storage/statistic/financial/O_2013Q2.xls";
my $file = "capital_gretai.xls";
getstore($url, $file);

Perl file unzip

use IO::Uncompress::Unzip qw(unzip $UnzipError) ;

$file_input = 'myfile.zip';
$file_output = 'myfile.xls';

unzip $file_input => $file_output, BinModeOut => 1;