Quote
foreach(@size)
{
my $i = 0;
$fileindex{$i}=$sizeindex{$file[$i]};
$i++;
}
Sorry, das ist ganz schoen umstaendlich und unsauber.
All das kann man etwas kuerzer fassen...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
use strict;
use warnings;
use vars qw(%files);
opendir(DIR, '.') or die $!;
$files{$_} = -s for grep -e && -f, readdir( DIR );
closedir(DIR);
printf("%s\t%s\n", human_readable_fsize($files{$_}), $_ )
for sort { $files{$a} <=> $files{$b} } keys %files;
sub human_readable_fsize {
my(@units) = qw(Bytes KB MB GB TB);
my $i = $_[0] >= 1099511627776 # 1024 ** 4
? 4 : $_[0] >= 1073741824 # 1024 ** 3
? 3 : $_[0] >= 1048576 # 1024 ** 2
? 2 : $_[0] >= 1024
? 1 : 0;
return sprintf('%.2f %s', $_[0] / 1024 ** $i, $units[$i]);
}
\n\n
<!--EDIT|coax|1116171965-->
,,Das perlt aber heute wieder...'' -- Dittsche