Chad Kellerman wrote:
> 
> Hey guys,

Hello,

>    I was working on a disk usage script.  Mainly using stat like DAn had
> in an earlier posting.  Buit when I saw Janek post I thought, "That's
> perfect,  Just what I was doing but about 8 lines less."  I incorporated
> it into my script but the waring message I can't figure out.  I am kinda
> new, but thanks for the help...
> 
> <--snip-->
> 
> use strict;
> use diagnostics;
> $|++;
> 
> use File::Find;
> use vars qw (@users $user $BLOCK_SIZE $TOTAL_SIZE $MB_SIZE);

Is there any reason that you are using 'use vars' and not our() or my()?


> @ARGV = ('/home') unless @ARGV;

Is there any reason that you are using @ARGV and not a scalar?


> $TOTAL_SIZE = 0;
> $MB_SIZE= 0;
> 
> opendir(DIRECTORY, "@ARGV") || die $!;
                     ^^^^^^^
opendir() can only open a single directory so using an array makes no
sense.  Using an array in quotes is the same as join( $", @ARGV ).


> @users = readdir(DIRECTORY);
> closedir(DIRECTORY);
> 
> foreach $user (@users) {
>         next if ($user eq ".") || ($user eq "..") ;
>         find(sub {$TOTAL_SIZE += -s if -f}, "$user");

You should use the special handle _ if you are using more than one file
test so that you don't stat the same file more than once.  You shouldn't
put quotes around single variables.

perldoc -q quoting

Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod
       What's wrong with always quoting "$vars"?


>         print "$user  $TOTAL_SIZE\n";
>         undef $TOTAL_SIZE;

You just want to reset this value to zero not undef it.

> }

You shouldn't use all upper case for variable names.

perldoc perlstyle


> <--/snip-->
> 
>   I had to undef $TOTAL_SIZE because it kept adding the users together
> and I could not figure a way to get the du individually.
> 
>   THe error message I am getting says something like this:
> 
> Use of uninitialized value in concatenation (.) or string at
>         /home/ckell/scripts/du.pl line 28 (#1)
> 
> but if the undef is taken out the warning messag is gone but I don't get
> the right results.



use strict;
use diagnostics;
$|++;

use File::Find;

my $dir = shift || '/home';

my $total_size = 0;

opendir DIR, $dir or die "Cannot open $dir: $!";
my @users = grep !/^\.\.?$/, readdir DIR;
closedir DIR;

for my $user ( @users ) {
    find( sub { -f and $total_size += -s _ }, $user );
    print "$user  $total_size\n";
    $total_size = 0;
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to