There's more than one way to do things | |
PerlMonks |
Re: How to sort a large flat file 90mb with PERL-- various ways/tradeoffs/watchoutsby jarich (Curate) |
on Jun 30, 2004 at 09:47 UTC ( [id://370718]=note: print w/replies, xml ) | Need Help?? |
First of all, welcome to Perl maxon11.
You would be vastly assisted by reading the various tutorials on this site, and getting yourself a good book about Perl. Randal Schwartz's "Learning Perl" might be perfect. I particularly recommend that you read the On asking for help and How (Not) To Ask A Question nodes as I feel that your questions here could have benefitted by your being more brief. At the very least, you can probably depend on us having access to the sort documentation already. ;) Even if Randal did sent it to you. The uninitialized value warning from sort.pudge.pl is probably a minor bug. If that's all it gave you however, then I wouldn't worry too much. It looks like it otherwise sorted your file. In the second case - yes you probably ran out of memory. How much memory are your programs allowed to take up? If you're on a Unix-like operating system then you can usually type in "ulimit" on the command line and find out. Mind you, if you're using a Unix-like operating system then you should probably use the unix sort. :) The difference between the two sort code listings that you provide is that the first makes several copies of the data in memory whereas the second does not. To explain how the second program works, I'll reformat it and add in some comments. I've also made some slight changes to make it a better program generally.
You ask how Perl knows to default sort the whole record in alphabetical order. This is answered right up the top of the sort documentation: If SUBNAME or BLOCK is omitted, "sort"s in standard string comparison order. That is, if you write sort @array then sort will sort alphabetically. I would presume that you actually want it to sort numerically. You can do this by writing: sort { $a <=> $b} @array just like it says in the documentation. Good luck with learing Perl. Hope this helps jarich
In Section
Seekers of Perl Wisdom
|
|