现在的位置: 首页 > 综合 > 正文

Perl使用总结

2013年01月13日 ⁄ 综合 ⁄ 共 1153字 ⁄ 字号 评论关闭

1 从CPAN安装模块

http://www.cpan.org/

搜索模块

找到后,安装,例如:

perl -MCPAN -e 'install HTML::WikiConverter'

2 debug

perl -d program_name
perl -d:Ptkdb program_name

需要Kt和Devel::Ptkdb,注意大小写,我安装的时候装了个小写,解决办法使用ln -s创建一个符号链接到小写。

http://perldoc.perl.org/perldebug.html

3 判断文件是否存在

if -e

http://perldoc.perl.org/functions/-X.html

4 1; in perl file

The file must return true as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with 1; unless you're sure it'll return true otherwise. But it's better just to put the 1; , in case you add
more statements.

http://perldoc.perl.org/functions/require.html

1 in the end of module means that module returns true to use/require statements. It can be used to tell if module initialization is successfull. Otherwise use/require will fail.

http://stackoverflow.com/questions/1940182/what-does-1-mean-in-perl

5 shift

shift and unshift do the same thing to the left end of an array thatpop and push do to the right end.

http://perldoc.perl.org/functions/shift.html

6 列出文件entry

$::dir="\.";
opendir( CONF, $::dir ) or die $!;
while( $::config = readdir( CONF ) ) {
        print "Traverse : $::config\n";
        next if( $::config !~ /([^\/]+)\.conf$/ );
        #$::config = readdir ( CONF );
        print "Found : $::config\n";
}

http://perldoc.perl.org/functions/readdir.html

抱歉!评论已关闭.