in reply to Re^4: Bolt on where a match is not found to a print script
in thread Bolt on where a match is not found to a print script
Does this fix it?
for my $m (m/$regex/g) { # Update: reworked $matched{$m} = 1; print "$file $_"; }
Full code:
#!/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> ) { for my $m (m/$regex/g) { # Update: reworked $matched{$m} = 1; print "$file $_"; } } } # Check all nums have been seen for my $num (@nums) { if (not exists($matched{$num})) { print "$num not found\n"; } }
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Bolt on where a match is not found to a print script
by AnomalousMonk (Archbishop) on Dec 06, 2017 at 17:27 UTC | |
Re^6: Bolt on where a match is not found to a print script
by QM (Parson) on Dec 07, 2017 at 16:57 UTC | |
Re^6: Bolt on where a match is not found to a print script
by Anonymous Monk on Dec 06, 2017 at 16:54 UTC |
In Section
Seekers of Perl Wisdom