Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Please let me know how can I minimize the code here to make the script run faster or give me some alternative unix commands.#!/usr/bin/perl -w use strict; use File::Find (); my $dir = shift; die "Not a directory: '$dir'\n" unless -d $dir; print "Blame for $dir\n"; my %blame = (); my $total = 0; my (%uid, %username, %name); while (my ($shortname, $pw, $uid, undef, undef, undef, $name) = getpwe +nt) { next if exists $username{$uid}; $username{$uid} = $shortname; $name{$uid} = $name; } sub wanted { my (undef, undef, undef, undef, $uid, undef, undef, $size) = l +stat($File::Find::name); $blame{$uid} += $size; $total += $size; } sub by_usage { $blame{$b} <=> $blame{$a} } File::Find::find({wanted => \&wanted}, $dir); print " Usage Login Comment\n"; foreach my $uid (sort by_usage keys %blame) { next if $blame{$uid} == 0; printf "%13s %12s %s\n", $blame{$uid}, $username{$uid}||$uid, +$name{$uid}||$uid; } printf "%13s total disk used\n", $total;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: would like add your enhancement
by moritz (Cardinal) on May 09, 2008 at 10:53 UTC |