I made a few mods to your script (BTW, very nice). I am using File::Recurse, got rid of a loop (sortedhash), and did some cool stuff with the labels. Hope this helps.
#!/usr/bin/perl -w # # This program will outline the top users of a file system. # use strict; use Getopt::Long; use File::Recurse; my $max_users=10; my @fs=(); my @file_list=(); my @dir_list=(); my %filehash; GetOptions( "fs=s@" => \@fs, "users=i" => \$max_users ); &help() unless @fs; foreach my $fs (@fs) { my %sorthash; undef(%filehash); print "$fs:\n"; recurse ( sub { my ($uid, $size) = (stat)[4, 7]; $filehash{$uid} += $size; }, $fs); my $count = 0; foreach my $uid ( sort {$filehash{$b} <=> $filehash{$a} } keys %fi +lehash) { next if ($uid eq ""); last unless $count < $max_users; my $name = (getpwuid($uid)) || "uid($uid)"; &printUser($name, $filehash{$uid}); $count++; } print "\n"; } sub printUser { my ( $user, $size ) = @_; my $label; my @labels = qw ( bytes Kb Mb Gb ); foreach my $power (reverse 0..$#labels){ if($size >= (1024**$power)){ $label = $labels[$power]; $size /= (1024**$power); last; } } printf " %-12s is using %7.2f %s\n", $user, $size, $label; } sub help() { print "Syntax:\n\t$0 [--users=i] --fs=/path1 [--fs=/path2] ...\n"; exit(0); }

In reply to RE: DiskUsage Calculator by Anonymous Monk
in thread DiskUsage Calculator by qi3ber

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.