Keep It Simple, Stupid | |
PerlMonks |
Re: Sorting A File Of Large Recordsby dingus (Friar) |
on Dec 10, 2002 at 20:01 UTC ( [id://218888]=note: print w/replies, xml ) | Need Help?? |
This could be a good choice to use An APL trick for the Schwartzian Transform as that is almost exactly the reason why I thought it up in the first place...
There are some subtelties, mostly specified above that help. The first trick (suggested by dmitri) is to set $/ to '-------'.$/ so that you get each record. If the file is far too big to fit into memory then the second is to create the sort based on the location within the file and the zip code - use tell() with each record. Other tricks may depend on whether the file is local or not (whether you can afford to read it multiple times) whether you want to sort on a secondary key as well and so on. Actually thinking about, assuming that you have sufficient memory and no secondary key you wish to sort on my prefered solution would be a two phase sort. Phase one is an insertion sort into a hash of zip codes. Then you read the file again and write out the sorted version. Disclaimer - code untested may contain horrible bugs Dingus Enter any 47-digit prime number to continue.
In Section
Seekers of Perl Wisdom
|
|