#!/usr/bin/perl use warnings; # The first parameter on the command line is the pattern to match # Note that if regex metacharacters are included here they must be escaped # or they will take on their normal function within the regular expression $pattern = shift @ARGV; # The rest of parameters are files to check the pattern against foreach $file (@ARGV) { # This should be familiar from Week 2 Exercises or pages 167-168 open FILE, "<$file" or die "Can't open $file for reading\n"; @contents = ; # This reads the entire file at once close FILE; $n = 0; foreach (@contents) # Check every line in the current file { chomp; $n++; if (/$pattern/) # For this pattern { print "$file $n: $_\n"; } } }