in reply to help with FS usage script using a data struct

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; } }