I'm no Saint, but I'll give what help I can. First, your questions:

1. It prints nothing for a couple of reasons.

It may seem like a bit of a dead horse on Perlmonks, but I'm going to reiterate some common advice. You should always use warnings or call perl with the -w switch unless you know exactly why you aren't. It gives you loads of helpful messages about things that could go wrong with your script. use strict is a good idea, too, but I'll admit I don't follow that one every time.

2. If all you are interested in is the size, then you can use a simple total for each user in %sum.

Side note here: On my computer, applying stat to a directory name does not get the size of the directory contents. In fact, "/my/dir/" is always a fixed size of 4096, even if it contains the latest download of Mozilla. You're not really getting much information about usage if you count the size of directories that way.

3. I don't know much about File::Find, but I'm just trying to get you started with what I do know. The code below does the job you describe, and hopefully it'll make the rest of your task easier. I did a little fiddling with the result output - that's just the kind of guy I am.

Note: Associating names with user IDs is left as an exercise (e.g., I'm feeling lazy).

#!/usr/bin/perl # fs.pl # Find filespace consumption per user for a given directory tree # # USAGE # perl fs.pl dir1 [dir2 ... dirN] use warnings; use strict; use File::Find; my %sum; # Add the size of a file to a tally for the file owner. sub wanted_user { my ($user,$size) = (stat($_))[4,7] or die "can't stat '$_': $!\n"; $sum{$user} += $size; } # MAIN EXECUTION while (<@ARGV>) { my $dir = $_; find (\&wanted_user, $dir); print "Usage Report for '$dir'\n"; print "USER\t USAGE\n"; foreach my $user (sort keys %sum) { printf "%s:\t%.2fMB\n", $user, $sum{$user}/1024/1024; } }

In reply to Re: help with FS usage script using a data struct by webfiend
in thread help with FS usage script using a data struct by neptuna

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.