# Revision 76

Date:
2008/04/08 21:05:42
Revision Log:
Files:

Removed

Modified
• ## trunk/sum.pl

2 2
3 3 use strict;
5 use Getopt::Long;
5 6
7 my \$human = 0;
8 GetOptions(
9 'human!' => \\$human,
10 );
11
6 12 my @lines;
7 13
8 14 my \$max_size = 0;

10 16 my \$rest_len = 0;
11 17 my \$sum = 0;
12 18
19 my @units = qw/b k M G/;
20 sub unit {
21 my \$v = shift;
22
23 return \$v unless \$human;
24
25 my \$o = 0;
26
27 while ( ( \$v / 10000 ) >= 1 ) {
28 \$o++;
29 \$v /= 1024;
30 }
31
32 if ( \$v >= 1 ) {
33 return sprintf("%d%s", \$v, \$units[\$o]);
34 } elsif ( \$v == 0 ) {
35 return 0;
36 } else {
37 return sprintf("%.1f%s", \$v, \$units[\$o]);
38 }
39 }
40
13 41 while(<>) {
14 42 chomp;
15 43 if (/\s*([\d\.]+)\s+(.+)/) {

60 88 foreach my \$l (@lines) {
61 89 my (\$size,\$r,\$tmpsum) = @{\$l};
62 90 # printf "%-50s\t[ + %-8d= %-8d ]\n",\$r,\$size,\$tmpsum;
63 printf "%-\${rest_len}s %\${size_len}d %-\${bar_size}s %\${sum_len}d\n",
64 \$r, \$size, bar(\$size, \$sum, \$tmpsum, \$sum), \$tmpsum;
91 printf "%-\${rest_len}s %\${size_len}s %-\${bar_size}s %\${sum_len}s\n",
92 \$r, unit(\$size), bar(\$size, \$sum, \$tmpsum, \$sum), unit(\$tmpsum);
65 93 }