I am attempting to sort by a field in a hash within a hash and I am
having a hard time finding the right direction. I want the print out to
sort from smallest to largest in size. Any help would be greatly
appreciated. 

Scott

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

# Set your size/time requirements
$minsize = 50;          # Expressed in Megabytes
$maxtime = 90;          # Expressed in days

# Define modules we need
use File::Find;
use Time::Local;

# Get defined inputs and convert them to something we can use
$nosmaller = ($minsize * 1024);
$nonewer = ($maxtime * 86400);
$time = timelocal($seconds, $minutes, $hours, (localtime)[3,4,5]);      
$timecomp = ($time - $nonewer);                                         

%tmp = ();
# setup temp hash
$count = 0;

sub wanted {
        my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
                $size, $atime, $mtime, $ctime,) = stat($_);
        if ($atime < $timecomp) {
                if ($size > $nosmaller) {
                        $count++;
                        my $filename = $File::Find::name;
                        my ($name) = getpwuid($uid);
                        my $osize = ($size / 1024 / 1024);
                        $tmp{$count}{owner} = $name;
                        $tmp{$count}{size} = $osize;
                        $tmp{$count}{file} = $filename;
                }
        }
}

File::Find::find({wanted => \&wanted}, @ARGV);

# Print out hash table
for $count ( keys %tmp ) {
        printf "%10s %12.2f MB $tmp{$count}{file} \n",
                $tmp{$count}{owner}, $tmp{$count}{size};
}
exit;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to