Regarding your question how $OFH writes to different files. I do it by building an array containing: (1) The name of the regular expression, (2) the regular expression, and (3) the output file handle using this code:
while (<DATA>) { . . . create $name, $rex and $FH . . . push @rexlist, [ $regex, $name, $FH ]; }
Then as we process the input file, we scan through our regular expressions, and for each one, we pull the regex, name and output file handle out of the array:
while (my $line = <$IFH>) { . . . # For each regular expression for my $r (@rexlist) { # Pull the regular expression, name and file handle out of our + array my ($rex, $name, $OFH) = @$r; # If the line matches the regex, write it to the file if ($line =~ $rex) { print $OFH $line; } } . . . }
Feel free to ask again if you need a bit more clarification.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re^3: Write to multiple files according to multiple regex
by roboticus
in thread Write to multiple files according to multiple regex
by Foodeywo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |