You need the Schwartzian Transform
I'd say it's doubtful. Clearly, stat is slow, but it's not a slouch, and the Schwartz Transform adds its own overhead. I suspect the sweet spot where the ST pulls ahead is higher than you think.
If we want to pursue this approach, an improvement will be to employ a Guttman-Rosler Transform:
my @sorted = map substr($_, 4) => sort map pack(`L',$_) . $_ => @files; # but see eyepopslikeamosquito's comment below
By being able to dip down and call the sort function without a code block will show greater benefits. With the proviso that one might have to pack with 8 byte 'Q' quads, for systems with filesizes larger than 2Gb.
With that in mind, it's probably all premature optimisation. I would wait until the snippet showed itself as being a performance pig before going to all this bother:
sort { -s $a <=> -s $b } @files
... does have the distinct advantage of being eminently readable.
- another intruder with the mooring of the heat of the Perl
In reply to Re^2: Sorting based on filesize.
by grinder
in thread Sorting based on filesize.
by heigold1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |