11.26. Regexp::Common

Example 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";
}


Example 11-7. examples/regex/regexp_common.txt


one
(two)
(three))
((three)
)four(
poop

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed