in reply to Re: Re: Formatting a large number of records
in thread Formatting a large number of records
You are opening and closing a file each time through the loop when the year isn't '02'. This could be a significant impact on your runtime if there are a lot of these records. It might be best to establish a hash of file handles and keep them open. Something like this (untested):
my %handles; my %count; sub get_file_handle { my $yr = shift; $count{$yr}++; return $handles{$yr} if exists $handles{$yr}; $handles{$yr} = IO::File ">>".$path."year$yr.txt"; }
I don't know what your OUTPUT handle is assigned to. If you put it in the hash with the key '02', you could remove the if ($year...) test inside your loop. Then, your valid line handling becomes:
print get_file_handle($year) "$newline\n";
You do a chomp on the record read from the file only to add a newline when you print to output. If the removal of the newline is not required by your validLine() routine, get rid of both.
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Formatting a large number of records
by Aristotle (Chancellor) on Dec 30, 2002 at 15:45 UTC |