[Melbourne-pm] finally there

David Dick ddick at aapt.net.au
Thu Dec 20 12:41:33 PST 2007


Mirko Fluher wrote:
> Happy to read any other useful comments as I am sure the above code can be improved.
> Cheers,
>
>   

hi mirko, i would plead with you to 'use strict' in all of your perl 
programs.  among other things, it will help detect typing mistakes in 
variable names.
something like the following.

--------------------------
#!/usr/bin/perl -w

use strict;
use File::Find;
use Date::Format;

my $dirname = "/dir1/fileserver/dir2/documents";

my %size;

find(sub {$size{$File::Find::name} = -s if -f;}, $dirname);
my @files = sort {$size{$b} <=> $size{$a}} keys %size;

foreach (@files)
{
        my ($uid, $mtime) = ((stat($_))[4,9]);
        my $userid = getpwuid($uid);
        my $date = time2str('%Y-%m-%d', $mtime);
        printf "%s,%s,%s,%s\n", $userid, $size{$_}, $date,$_;
}
--------------------------



More information about the Melbourne-pm mailing list