in reply to finding top 10 largest files
You have file size as the key to your hash so sort just needs to be:
for my $key( sort { $b <=> $a } keys %sizehash ) { # blah }
HOWEVER -> From the practical point of view your data structure is ass about. You really want the full path as the key (unique) not the file size (not unique). For example if you have two files of 1,000,001 bytes then only the second one you find will be seen as it will overwite the filename stored with the 1,000,001 byte key.
To sort a hash numerically by value once you fix the BUG you would do:
for my $file( sort { $sizehash{$b} <=> $sizehash{$a} } keys %sizehash +) { my $size = commas($sizehash{$file}); last if $y++ > 10; print "$size: $file\n"; }
cheers
tachyon
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: finding top 10 largest files
by bfdi533 (Friar) on Mar 02, 2004 at 18:02 UTC | |
by tachyon (Chancellor) on Mar 03, 2004 at 01:38 UTC |