in reply to Re: separating every set of textline
in thread separating every set of textline
If the different files can be determinated before the loop, you can open all of them and the use the apropiate (i.e., keeping them in a hash). When they're not known until runtime (it was my case), I used a closure returning lexical filehandles from a hash. Something like that:
{ my %handles; # Closure keeps the hash between function calls sub handle{ my $city = shift; my $temp; unless ($handles{$city}){ open $temp, ">", "$city.txt" or die "$!"; $handles{$city} = $temp; } return $handles{$city}; } }
It worked for me and reduced the execution time about a 50%. Hope it helps.
|
|---|