good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
(jeffa) Re: Sorting Numbersby jeffa (Bishop) |
on Nov 06, 2001 at 07:13 UTC ( [id://123491]=note: print w/replies, xml ) | Need Help?? |
I really wish you would have included some sample data - it
doesn't have to be the exact data for obvious legal reasons,
but just some data of similar structure. This code is quite
horrible, it is obvious that someone was attempting to make
modular, reusable code, but fell short of the mark.
Looks like the idea is to sort on the results of a user defined sort routine (that relies on global variable no less) that gets its input from a subroutine that turns its first argument into a filehandle and returns it. This is wrong, wrong, wrong, wrong! Instead, you should open the file, process it into a data structure - looks like a 2-d array would be good to me, THEN sort the data structure. The subroutine sort_func is repeatedly splitting the lines to do it's work - this is extremely wasteful, especially if you need the pieces of the lines again later on. Here is some sample code to play with. Since you didn't supply any test data (hint hint), i'll make up my own. Also, i am going to use the DATA handle instead of reading from a file. You should have no troubles changing this to fit your needs:
Hope this helps, and don't forget to erase the comments
when you are done ;)
UPDATE - changed multi-line comment style from # to POD
In Section
Seekers of Perl Wisdom
|
|