7C00.ME/houmu 2013-05-03

Perl正则表达式测试程序

参考《Perl语言入门》的一个正则表达式简单测试程序:

#!/usr/bin/perl
use warnings;
use strict;

my $pattern=$ARGV[0];
if(not $pattern){
    print "Usage: ./ret.pl PATTERN\n";
    exit;
}
print "The pattern is m{$pattern}.\n";
print "Ctrl + D to exit.\n";
print ">";
while(<STDIN>){
    chomp(my $line = $_);
    if($line =~ m{$pattern}){
        print "matched: '$`<$&>$''.\n";
    } else {
        print "not matched.\n";
    }
    print ">";
}