Consider:
use strict; use warnings; my @insert1 = qw(1 1 1); my @insert2 = qw(2 2 2); my @inserts = (\@insert1, \@insert2); my $outfile = 'delme.txt'; my $ins = 0; open OUTFILE, '>', $outfile; print OUTFILE <<DATA; first second third 1 2 3 x y z DATA close OUTFILE; for (@inserts) { insert (@$_); local @ARGV = $outfile; local $/ = undef; print <>; } ...
Prints:
insert called:0 first second third 1 1 2 3 1 x y z 1 insert called:1 first second third 1 2 1 2 3 1 2 x y z 1 2
Note that the bogus result from your reworking of my code was due to $/ being set to undef and therefore the <FILE2> seeing the entire file as one line on the second iteration. Sometimes I include "interesting" ways of doing stuff to make you explore the language and the documentation a little. In this case read perlvar to gain a little insight. ;)
In reply to Re^3: weird file write problem
by GrandFather
in thread weird file write problem
by monkeyking
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |