I can suggest several improvements to the code you have posted.
Declare all variables in the smallest possible scope. Your declaration of all variables at the start of the file largely defeats your use of strict.
Lexical file handles are much easier to manage than globs.
The three argument form of open would make the intention clearer.
Storing your file data in an array of hashes rather than in parallel arrays probably would not make any difference in speed, but it would help your readers by keeping related data together.
Store you regexes as regexes (use qr//) rather than strings. It is probably faster, and it certainly makes the intention clearer.
Note: The $INPUT_RECORD_SEPARATOR is a string not a regex.
UNTESTED
#!perl use strict; use warnings; use FindBin; my $dir = "$FindBin::Bin/../rxo"; opendir( my $dh, $dir ) || die "can't opendir $dir: $!"; my @inputs = readdir($dh); closedir $dh; splice @inputs, 0, 2; my @dispatch; foreach (@inputs) { my $outfile = "$FindBin::Bin/../blocks/$_"; open my $ofh, '>', $outfile || die; my $file = "$FindBin::Bin/../rxo/$_"; open my $fh, '<', $file || die; my $regex = <$fh>; close $fh; push @dispatch, { file => $ofh, regex => qr/$regex/ }; } while ( my $line = do{ local $/ = 'END'; <> } ) { foreach (@dispatch) { print { $_->{file} } $line if $line =~ $_->{regex}; } }
In reply to Re^3: Write to multiple files according to multiple regex
by BillKSmith
in thread Write to multiple files according to multiple regex
by Foodeywo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |