James Kipp wrote at Tue, 04 Jun 2002 16:24:04 +0200:
> ...
> here is some code:
> ----------
> use File::Find;
> find (\&wanted_user, "$dir");
>
> sub wanted_user
> {
> %sum = ();
> next unless (-d $_);
> ($user,$size) = (stat($_))[4,7] or die "can't stat: $!\n"; push (
>@{$sum{$user}}, $size );
> }
> }
> }
> foreach $user (sort keys %sum) {
> print "$user: @{$sum{$user}}\n";
> }
> ----------------
>
> questions:
> 1. it prints nothing. it should at least print something like 11847: 44645, 45466....
next unless (-d $_) means that you ignore the file if it isn't a directory.
That means you'll browse through all subdirectories without looking at any file.
>
> 2. after question 1 is solved, what is the best way to add the size into a total.
>something like:
> push ( @{$sum{$user}}, ++$size ); ?
$sum{$user} += $size;
>
> 3. also I may have to get rid of the stat() way of getting the user and size because
>there are
> some dirs that have dirs and files that i do not have access too and will generate
>erros instead
> of stating. i know i can parse a `ls -ld` but is there a better way?
perldoc -f -X
e.g. -f -s $file returns the size of the file.
Greetings,
Janek
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]