Perl初学笔记之Hello World
工作需要开始学Perl,下载个Window版(5.16)的:下载链接
http://www.activestate.com/activeperl/downloads
安装好了之后,写第一个perl程序
#!/usr/bin/perl print"Hello,World!\n";
运行结果:(很像Python哦)
c:\Perl>perlHelloWorld.pl Hello,World!
接着学了下:cpan,虽然不知道这家伙具体是干嘛,应该是能安装各种包,9000多种。
命令如下:看第二次输出的结果,应该是类似于数据库的东东吧。
c:\Perl>cpanApp::cpanminus Setupgccenvironment-3.4.5(mingw-vistaspecialr3) CPAN:Term::ANSIColorloadedok(v4.02) CPAN:Storableloadedok(v2.34) Reading'C:\Perl\cpan\Metadata' DatabasewasgeneratedonFri,07Mar201413:06:13GMT CPAN:Module::CoreListloadedok(v2.80) App::cpanminusisuptodate(1.7001).
然后用cpanm安装模块,命令如下:(cpanmModule::Name)
c:\Perl>cpanmYAML Setupgccenvironment-3.4.5(mingw-vistaspecialr3) -->WorkingonYAML Fetchinghttp://www.cpan.org/authors/id/I/IN/INGY/YAML-0.90.tar.gz...OK ConfiguringYAML-0.90...OK BuildingandtestingYAML-0.90...OK SuccessfullyinstalledYAML-0.90 1distributioninstalled
如果实在不晓得如何用的话:cpanm--help //-->会看到很多提示。
c:\Perl>cpanm--help Setupgccenvironment-3.4.5(mingw-vistaspecialr3) Usage:cpanm[options]Module[...] Options: -v,--verbose Turnsonchattyoutput -q,--quiet Turnsoffthemostoutput
看上面的安装过程,好像是可以执行cpanmLink,果然是可以:
c:\Perl>cpanmhttp://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Alt-Base-0.0 2.tar.gz Setupgccenvironment-3.4.5(mingw-vistaspecialr3) -->Workingonhttp://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Alt-Base-0. 02.tar.gz Fetchinghttp://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Alt-Base-0.02.tar .gz...OK ConfiguringAlt-Base-0.02...OK ==>Founddependencies:Alt -->WorkingonAlt Fetchinghttp://www.cpan.org/authors/id/I/IN/INGY/Alt-0.04.tar.gz...OK ConfiguringAlt-0.04...OK BuildingandtestingAlt-0.04...OK SuccessfullyinstalledAlt-0.04 BuildingandtestingAlt-Base-0.02...OK SuccessfullyinstalledAlt-Base-0.02 2distributionsinstalled
然后开始写了个文件操作的脚本,里面有个Path::Class模块。
usePath::Class; C:\Perl\Learn>perlFindFile.pl Can'tlocatePath/Class.pmin@INC(@INCcontains:C:/Perl/site/lib/MSWin32-x86- multi-threadC:/Perl/site/libC:/Perl/lib.)atFindFile.plline4. BEGINfailed--compilationabortedatFindFile.plline4.
看提示,像没有安装该包,安装了下该包,结果果然没报这种错误:
C:\Perl\Learn>cpanmPath::Class Setupgccenvironment-3.4.5(mingw-vistaspecialr3) -->WorkingonPath::Class Fetchinghttp://www.cpan.org/authors/id/K/KW/KWILLIAMS/Path-Class-0.33.tar.gz.. .OK ConfiguringPath-Class-0.33...OK BuildingandtestingPath-Class-0.33...OK SuccessfullyinstalledPath-Class-0.33 1distributioninstalled
完~