Perl初学笔记之Hello World
程序员文章站
2022-03-14 21:38:10
工作需要开始学perl,下载个window版(5.16)的: 下载链接
安装好了之后,写第一个perl程序
复制代码 代码如下:
#!/usr/bin/perl...
工作需要开始学perl,下载个window版(5.16)的: 下载链接
http://www.activestate.com/activeperl/downloads
安装好了之后,写第一个perl程序
复制代码 代码如下:
#!/usr/bin/perl
print "hello,world!\n";
运行结果: (很像python哦)
复制代码 代码如下:
c:\perl>perl helloworld.pl
hello,world!
接着学了下:cpan,虽然不知道这家伙具体是干嘛,应该是能安装各种包,9000多种。
命令如下:看第二次输出的结果,应该是类似于数据库的东东吧。
复制代码 代码如下:
c:\perl>cpan app::cpanminus
set up gcc environment - 3.4.5 (mingw-vista special r3)
cpan: term::ansicolor loaded ok (v4.02)
cpan: storable loaded ok (v2.34)
reading 'c:\perl\cpan\metadata'
database was generated on fri, 07 mar 2014 13:06:13 gmt
cpan: module::corelist loaded ok (v2.80)
app::cpanminus is up to date (1.7001).
然后用cpanm安装模块,命令如下: (cpanm module::name)
复制代码 代码如下:
c:\perl>cpanm yaml
set up gcc environment - 3.4.5 (mingw-vista special r3)
--> working on yaml
fetching http://www.cpan.org/authors/id/i/in/ingy/yaml-0.90.tar.gz ... ok
configuring yaml-0.90 ... ok
building and testing yaml-0.90 ... ok
successfully installed yaml-0.90
1 distribution installed
如果实在不晓得如何用的话: cpanm --help //-->会看到很多提示。
复制代码 代码如下:
c:\perl>cpanm --help
set up gcc environment - 3.4.5 (mingw-vista special r3)
usage: cpanm [options] module [...]
options:
-v,--verbose turns on chatty output
-q,--quiet turns off the most output
看上面的安装过程,好像是可以执行cpanm link,果然是可以:
复制代码 代码如下:
c:\perl>cpanm http://search.cpan.org/cpan/authors/id/s/sh/sharyanto/alt-base-0.0
2.tar.gz
set up gcc environment - 3.4.5 (mingw-vista special r3)
--> working on http://search.cpan.org/cpan/authors/id/s/sh/sharyanto/alt-base-0.
02.tar.gz
fetching http://search.cpan.org/cpan/authors/id/s/sh/sharyanto/alt-base-0.02.tar
.gz ... ok
configuring alt-base-0.02 ... ok
==> found dependencies: alt
--> working on alt
fetching http://www.cpan.org/authors/id/i/in/ingy/alt-0.04.tar.gz ... ok
configuring alt-0.04 ... ok
building and testing alt-0.04 ... ok
successfully installed alt-0.04
building and testing alt-base-0.02 ... ok
successfully installed alt-base-0.02
2 distributions installed
然后开始写了个文件操作的脚本,里面有个path::class模块。
复制代码 代码如下:
use path::class;
c:\perl\learn>perl findfile.pl
can't locate path/class.pm in @inc (@inc contains: c:/perl/site/lib/mswin32-x86-
multi-thread c:/perl/site/lib c:/perl/lib .) at findfile.pl line 4.
begin failed--compilation aborted at findfile.pl line 4.
看提示,像没有安装该包,安装了下该包,结果果然没报这种错误:
复制代码 代码如下:
c:\perl\learn>cpanm path::class
set up gcc environment - 3.4.5 (mingw-vista special r3)
--> working on path::class
fetching http://www.cpan.org/authors/id/k/kw/kwilliams/path-class-0.33.tar.gz ..
. ok
configuring path-class-0.33 ... ok
building and testing path-class-0.33 ... ok
successfully installed path-class-0.33
1 distribution installed
完~
上一篇: 软文推广的人群如何定向投放?
下一篇: Perl学习笔记之CPAN使用介绍
推荐阅读