in reply to Hash/file --> doesn't seem to work
Probably you would be better to construct a regular expression using Regexp::Assemble from the hash keys and perform a single pass through the file. Consider:
use strict; use warnings; use Regexp::Assemble; my %hash_table = (12345 => 1, 8976 => 2, 1046 => 3); my $assemble = Regexp::Assemble->new (flags => 'i'); $assemble->add (keys %hash_table); my $match = $assemble->re (); while (<DATA>) { chomp; my ($objid, $other) = split; if ($objid =~ /($match)/) { print "$1 is present in $objid\n"; } } __DATA__ 012345998 line matches 000104600 line matches 012389710 line doesn't match
Prints:
12345 is present in 012345998 1046 is present in 000104600
|
|---|