sort {...} chomp <DATA>;
print map { substr( $_, 16 ) } sort map { /^(\d+) # digits of type (\D+) # type character (\d+) # part (\D*) # detail (optional) R(\d+) # revision count B?(\d*) # alternate count (optional) \.(vec|ras) # file extension \s+$ # trailing whitespace /x ? sprintf( '%3s%03d%03d%2s%03d%1d%1s', # numbers add up to + 16 $7, 999 - ($6 || 0), $1, $2, $3, $5, $4, ) . $_ : ('x' x 16) . $_ } <DATA>;
The idea is that you add a prefix to the data you want to sort, in order to be able employ a bare sort. Once the array hits the sort code, you are running a C speed until the sort is done. No more perl op-codes for this baby. At the other end of the sort, you throw away the prefix.
Note how I create the inverse of the alt count so that the normal compare still works. (The sprintf may have to be tailored to suit). Also note how I create a dummy prefix in case the regexp fails. For debugging, comment out the map that strips off the prefix.
At least that way you can then set a breakpoint easily with b part_sort to see why the silly thing isn't working.sub part_sort { ... } sort part_sort <DATA>;
will do the job just as well.print sort part_sort <DATA>;
In reply to Re: complex sort
by grinder
in thread complex sort
by mkmcconn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |