Blob
1 #!/usr/bin/perl3 # Modify the program from Exercise 2 to use Regexp::Assemble so you have4 # one pattern instead of an array of patterns.6 use v5.24;7 use warnings;8 use strict;9 use utf8;10 use local::lib;11 use Getopt::Std;12 use Regexp::Assemble;14 my %opts;15 getopt("p:", \%opts);16 if (defined($opts{p}) && scalar(%opts) == 1) {17 open my $fh, "<", $opts{p} or die "Unable to open '$opts{p}': $!";18 my @patterns;19 my $ra = Regexp::Assemble->new;20 while (<$fh>) {21 chomp;22 $ra->add($_);23 }24 print "Type some input:\n\n";25 while (<>) {26 # print "$ra: $_\n";27 my $re = $ra->re;28 print "$.: $_" if /$re/;29 #print "$.: $_" if $ra->match($_);30 }31 } else {32 die "Usage: $0 -p file";33 }