in reply to Hash checking
No need to use a hash if you're just reading numbers from a file. Use an array instead:
#!/usr/bin/perl use strict; use warnings; my $file = 'AXP_FACS.DAT'; open my $FH, '<', $file or die "Error opening file: $!"; my @faclist = (<$FH>); % Read all lines into the array close $FH; chomp @faclist; % Remove newlines from each entry. my @numbers = 1..5000; foreach my $integer ( @numbers ) { unless ( grep { /\b$integer\b/ } @faclist ) { print "Not found: $integer\n"; } }
The '\b' at the start and end of the grep regular expression matches the entire number, not just a single digit.
njcodewarrior
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Hash checking
by GrandFather (Saint) on Apr 25, 2007 at 22:12 UTC | |
by njcodewarrior (Pilgrim) on Apr 28, 2007 at 18:28 UTC |