http://qs321.pair.com?node_id=1204947


in reply to Bolt on where a match is not found to a print script

Something like this (untested):
#!/usr/bin/env perl use strict; use warnings; my @files = <c:/perl64/myfiles/*>; # record matching regexes our %matched; my @nums = ('1203', '1204', '1207'); my $regex = '\b(' . join('|', @nums) . ')\b'; # update: fixed + to . for my $file ( @files ) { open my $file_h, '<', $file or die "Can't open $file: $!"; while ( <$file_h> ) { if (my ($match) = m/$regex/) { $matched{$match} = 1; print "$file $_"; } } } # Check all nums have been seen for my $num (@nums) { if (not exists($matched{$num})) { print "$num not found\n"; } }

I would probably remove the @files and pass them on the command line (changing the for loop to while (<>)).

You might also do something more generic around the numbers, and allow those to be passed on the command line as well -- but this will take some command line parsing, or one of the GetOpt modules.

Update: Fixed capture problem, as noted by AnomalousMonk.

Update 2: Fixed concatenation issue.

-QM
--
Quantum Mechanics: The dreams stuff is made of