One way to do it is to pass the $out handle into the printdata function. Beware of commata after $out in this example:
use strict; use warnings; sub printdata { my $out = shift; my $data = shift; $$data{"User-Agent"} //= "--"; print $out join "|", @$data{ ( "Arrival Time", "From", "To", "User +-Agent" ) }; print $out "\n\n"; %$data = (); } open my $out, ">", "tmp.txt"; my %data; my ($item, $value); print $out "Arrival Time|From|To|User-Agent\n\n"; while(<DATA>){ chomp; next unless ($item, $value) = /^(.*?): (.*)/; printdata $out, \%data if $item eq "Arrival Time" and %data; $data{$item} = $value; } printdata $out, \%data;
Alternatively, you could assemble a string in printdata, return it from the sub and print later.
In reply to Re^3: Arranging multiple lines
by hdb
in thread Arranging multiple lines
by r2ro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |