樹心幽徑

« 20190105-0107將Ubuntu1604的Linux核心由4.4.0-121更新成linux-4.20.0 | Main | 20190109在Ubuntu1604安裝VirtualBox5.1 »

20190107在windows7安裝strawberryperl及模組Path::Tiny、Spreadsheet::Read並使用perl語言來列出目錄內容(p1.pl)及讀取EXCEL工作表(p2.pl)
2019/01/07,09:13

ref:http://chu246.blogspot.com/2017/03/strawberry-perl-for-windows.html

(1)自官方網站 http://strawberryperl.com/ 下載並執行之

64位元版的安裝程式:strawberry-perl-5.28.1.1-64bit.msi

使用預設安裝資料夾C:\Strawberry

(2)安裝Path::Tiny perl modules (libraries) from http://www.cpan.org/

C:\perl>cpan Path::Tiny

Loading internal logger. Log::Log4perl recommended for better logging
CPAN: CPAN::SQLite loaded ok (v0.212)
CPAN: LWP::UserAgent loaded ok (v6.36)
Fetching with LWP:
http://cpan.strawberryperl.com/authors/01mailrc.txt.gz
CPAN: YAML::XS loaded ok (v0.75)
Fetching with LWP:
http://cpan.strawberryperl.com/modules/02packages.details.txt.gz
Fetching with LWP:
http://cpan.strawberryperl.com/modules/03modlist.data.gz
Creating database file ...
Done!
CPAN: Module::CoreList loaded ok (v5.20181130)
Path::Tiny is up to date (0.108).

(2b)編寫p1.pl

#!/usr/bin/perl
use strict;
use Path::Tiny;
my $dir = path('/','windows');
my $iter = $dir->iterator;
while (my $file = $iter->()) {
    next if $file->is_dir();
    print "$file\n";
}

my $nm ='SmallFlower';
print "hi $nm \n";
(2c)執行p1.pl

C:\perl>perl p1.pl

:

/windows/twunk_32.exe
/windows/unliu.exe
/windows/VB.INI
/windows/win.ini
/windows/WindowsShell.Manifest
/windows/WindowsUpdate.log
/windows/winhlp32.exe
/windows/WLXPGSS.SCR
/windows/WMSysPr9.prx
/windows/wplog.txt
/windows/write.exe
hi SmallFlower

(3)安裝Spreadsheet::Read模組(用以讀取Excel試算表)

C:\perl>cpan Spreadsheet::Read

:

C:\STRAWB~1\c\bin\gmake.exe install UNINST=1 -- OK

(3b)編寫p2.pl

#!/usr/bin/perl
use strict;
use Spreadsheet::Read;
my $workbook = ReadData ("data.xls");
print $workbook->[1]{A3} . ":" . $workbook->[1]{B3} . ":" . $workbook->[1]{C3} ."\n";

(3c)data.xls內容

id name age
n01 tigar01 20
n02 tigar02 40
n03 tigar03 60
n04 tigar04 80
n05 tigar05 100
n06 tigar06 120
n07 tigar07 140
n08 tigar08 160
n09 tigar09 180
n10 tigar10 200
n11 tigar11 220
n12 tigar12 240

(3d)執行p2.pl

C:\perl>perl p2.pl
n02:tigar02:40

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType