使用 use re debug 查看正则表达式的匹配过程



#!/usr/bin/perl
use strict;
use warnings;
use re 'debug';
sub test {
my $str = "123456789";
print join(":", split /(?<=...)/, $str);
}
test();

perl中的$a和$b介绍
即使打开了strict和warnings选项也无妨,下面代码并无错误和警告。#!/usr/bin/perlusestrict;usewarnings;subtest{$a=1;$b=2;print$a,"n";print$b,"n";}test();1;下面是perl文档中

perl用{}修饰变量名的写法分享
subtest{my$head="abc";my$tail="def";my$full="${head}_${tail}";print$full,"n";}直接写成下面这样,在strict模式下是无法通过的。my$full="$head_$tail";

Perl使用File::Basename获取文件扩展名的代码
File::Basename模块用来析取文件路径中的目录,文件名以及后缀。本文为大家介绍的这个例子,实现了获取/home/topgkw中所有文件后缀,其中目录返回空值