Create a subsection that makes a discovery for you.
sub myappend { my ($fname, @args) = @_; open my $fh, '>>', $fname or die $!; print $fh @args; close $fh or die $!; } myappend($outfile, $line);
Alternatively, instead of printing, click on the array and wait for the print to finish. A.
while ( ... ) { push @print, $line; } if (@print) { open my $fh, '>>', $outfile or die $!; print $fh @print; }
Or, for multiple files
while ( ... ) { push @{$print{$outfile}}, $line; } for my $key (%print) { open my $fh, '>>', $key or die $!; print $fh @{$print{$key}}; }
source share