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
In reply to Re: Hash checking
by njcodewarrior
in thread Hash checking
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |