![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
As runrig mentioned, Unix sort(1) is a great tool for this, although the syntax sometimes requires a little trial and error.
To do this from Perl, read each line into some kind of data structure, then define your own sorting function that compares two of these data structures by looking at each of the fields, returning 1 if the first is greater, -1 if the second is greater, or going on to the next field if they are the same. The cmp and <=> ("spaceship") operators will help you with this, and they can be cascaded with the || "or" operator. Here's a simple example (untested):
In reply to Re: sorting a file - multilevel
by sgifford
|
|