11.26. Regexp::CommonExample 11-6. examples/regex/regexp_common.pl #!/usr/bin/perl
use strict;
use warnings;
use Regexp::Common;
my $file = 'regexp_common.txt';
if (@ARGV) {
$file = shift;
}
open(my $data, '<', $file) or die "Could not open $file\n";
while (my $line = <$data>) {
chomp $line;
print "LINE: '$line'";
if ($line =~ /$RE{balanced}{-parens=>'()'}/) {
print " balanced parentheses";
}
if ($line =~ /^$RE{lingua}{palindrome}$/) {
print " a palindrome";
}
if ($line =~ /$RE{profanity}/) {
print " a four letter word";
}
print "\n";
}
|
Follow me: