Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'm guessing that this is still in "test" stages... it does not look like you have 60000 elements in your regex yet. ;)
It's looks like your patterns are supposed to match whole fields -- for example, "01005;11200" should match a line like this: but it should not match a line like this: The code you posted will match both lines, because the regex does not include ";" before and after the long conjunction of field values. Since you seem to be dealing with flat-table data, and your regex patterns involve matching certain combinations of third and fourth column values on each table row, you should consider treating handling things in a more table-like manner: read the target patterns into a hash, then read each row of the flat table file, pull out the 3rd and 4th fields, and see if they consistute an existing hash key. In any case, you do want to make sure your script will load your target patterns from a list file, rather than putting all the values in the perl code like you've done here. For example:
As for this comment of yours: i use noIf others, with less knowledge of perl than you have, are going to be altering this script, then that's the most important reason to include use strict; use warnings; -- that way, when they screw something up, there's a much better chance that the problem will be caught (and explained) before things get worse. (If these other people are just making adjustments to the list of target patterns, that is another very good reason for keeping that list in a separate file, so it can be updated without having to touch the perl script.) One last point: if your target patterns are not always being sought in the same columns of the table -- e.g. sometimes your target string is expected to match columns 3 and 4, and other times it is expected to match columns 5 and 6 -- then you might need to revert back to the regex approach. In that case, you should assign the conjunction of strings to a scalar, and form the regex like this:
In reply to Re^2: Filter script with pattern and an array
by graff
|
|