http://www.perlmonks.org?node_id=1163353


in reply to Sort directory by file size

That's probably the common trap of readdir: it returns the file names, not file paths.

Fix:

my @sDir = sort { -s "$dir/$a" <=> -s "$dir/$b" } readdir $D1;

If the number of files is high, asking for each file's size several times might slow the program significantly. Schwartzian transform should help.

my @sDir = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -s "$dir/$_" ], readdir $D1;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,