UT 123456789
1234
9876
1234
some additional string information
THE_END
UT 987654321
1234
2345
some additional string information
THE_END
UT 1928374756
4321
2567
1234
THE_END
some additional string information
UT 5647382910
1234
2435
5678
some additional string information
THE_END
notice I changed END to THE_END to make it more unique, since other lines may accidentially contain the string "END" and I cant use regex "^END"
the current code is:
#!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 $/ = 'THE_END'; <> }) {
foreach (@dispatch) {
print { $_->{file} } $line if $line =~ $_->{regex};
}
}
|