in reply to Re: separating every set of textline
in thread separating every set of textline

Only note that if the file is big, and there is not a lot of different files to create, calling open everytime a file must be update can be a considerable overhead (I've been in the same situation just a few days before).

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.