That assumes that the values in your hash are all "safe", in the sense that they don't contain any regex magic characters, like brackets, *, ?, +, period, slash, backslash, and so on.my $value_regex = join( '|', values %msgDefn ); # actually, use anony +monk's version below... while ( <FILEHANDLE> ) { print if ( /$value_regex/ ); }
If the values might contain things of that sort, you could handle it like this (but YMMV, depending on what's really in your data):
Now, if you ultimately need to know which hash key contains the value that actually matched a given line from the file, then you'd really want to build a reverse hash, as suggested in the 2nd reply.my $value_regex = join( '|', map { '\Q'.$_.'\E' } values %msgDefn );
Update (forgot to mention): Naturally, lots of other caveats apply, such as false-alarm matches on substrings (e.g. a value like "table", treated as above or as in the OP, would match on a line that contains "stable" or "tablet", which might not be what you want.
In reply to Re: Parse a huge file and match the lines against a hash entry
by graff
in thread Parse a huge file and match the lines against a hash entry
by snra_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |