|
|
| Welcome to the Monastery | |
| PerlMonks |
Re: schwartzian transform problem - Solvedby johngg (Canon) |
| on Feb 28, 2025 at 11:38 UTC ( [id://11164099]=note: print w/replies, xml ) | Need Help?? |
|
An alternative to the ST is a GRT. In a do block read the data with no line buffering from a filehandle (in this script a HEREDOC) and split into records at points not preceded by start of string (to avoid an empty first record) and followed by the ">>>" which starts each record. Each record passes into a map where the digits preceding the % sign are captured then packed as a 32-bit network order value (logical NOT applied as we want descending numerical order) concatenated with the whole record packed as a string. This is then passed to a simple lexical sort and then into a second map which unpacks the record by skipping the first four bytes which is the number used to sort. The script ...
The output ...
I hope this is of interest. Cheers, JohnGG
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||