in reply to Write to multiple files according to multiple regex
This code is untested, but maybe it already works
# 1. elide manually managed count variable # 2. read current line into an actual variable while(my $line = <$fh_bigfile>) { # 3. let perl manage the count variable for my $i (0..$#inputs) { # 4. wrong sigil, use $...[$i] instead of @...[$i] # 5. explicitely refer to the line to print it # 6. enclose file handle in braces to make it more obvious print {$filehandles[$i]} $line if (/$regex[$i]/../^END_OF_BLOCK/); } }
The most important changes are 2., 4. and 5.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Write to multiple files according to multiple regex
by Foodeywo (Novice) on Jul 21, 2015 at 12:02 UTC | |
by Monk::Thomas (Friar) on Jul 21, 2015 at 12:53 UTC | |
by Foodeywo (Novice) on Jul 21, 2015 at 13:03 UTC |