Keep It Simple, Stupid | |
PerlMonks |
Re: Sorting with perlby RMGir (Prior) |
on Aug 12, 2002 at 13:06 UTC ( [id://189472]=note: print w/replies, xml ) | Need Help?? |
(Edit: See Sorting with perl for a reformatted version of the question, and other answers).
I'm going to try to answer your question, but it would have been easier if you'd used the <code> and a few <p>aragraph tags to make it more readable. Please check out Writeup Formatting Tips. 1st file has words that are in specific order like this: (not alphabetic) GAVSTE GAVARC GAVADA GAVIMM GAVSP So you open up the first file, and read it into a hash that defines the sort order: (I'm assuming there's newlines between the words in the first file) It is "order quide" for sorting 2nd file in flatfile (delimiter is "|"): GAVARC 10.3. Tahkoluoto 1m SOMMOL 10.3. Tahkoluoto 7m GAVSTE 7.4. Preiviiki 1p GAVARC 7.4. Preiviiki 2p SOMMOL 16.3. Kallo 6m I have to guess at where the newlines are, so I'm going to assume the 2nd file looks like: (continued from previous code:)
For more details see Schwartzian Transform. A higher performance approach is the Guttman Rosler Transform but it's a bit more complicated to follow. -- Mike
In Section
Seekers of Perl Wisdom
|
|