3 # Write a program to read in a list of patterns from a file. Precompile the
4 # patterns and store them in an array. For example, your patterns file
9 # (The\s+)?(Skipper|Professor)
11 # Prompt the user for lines of input, printing the line number and text for
12 # each line that matches. The $. variable is useful here.
23 if (defined($opts{p}) && scalar(%opts) == 1) {
24 open my $fh, "<", $opts{p} or die "Unable to open '$opts{p}': $!";
28 push @patterns, eval { qr/$_/ };
30 print "Type some input:\n\n";
32 print "$.: $_" if $_ ~~ @patterns;
35 die "Usage: $0 -p file";