in reply to efficiently printing to 30 files
Is there any reason that you want to print as soon as you see someone's name? Why not instead just push to a hash of arrays, then dump the information out at the end? That way you won't have 30 file handles open at once (that used to be limited to 20 handles for C programs but Perl no doubt handles that nicely).
foreach my $n (keys %emp) { push(@{$data{'A'}},$emp{$n}{'Emp'}) if $emp{$n}{'Org'}=~/ABC/; push(@{$data{'B'}},$emp{$n}{'Emp'}) if $emp{$n}{'Org'}=~/DEF/; }
You may want to initailize the hash of arrays to start with so as to avoid those ugly warnings. Afterwards you can dump the data to files one by one.
--t. alexforeach(keys %data){ open(DATA,">group$_.txt")||die"Couldn't open file for $_:$!"; print DATA join("\n",@{$Data{$_}}); close(DATA); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: efficiently printing to 30 files
by larsen (Parson) on Mar 06, 2003 at 22:23 UTC | |
by talexb (Chancellor) on Mar 07, 2003 at 15:31 UTC | |
by larsen (Parson) on Mar 08, 2003 at 11:09 UTC |