- first note on your code is that you blatantly waste CPU cycles with double-quotes interpolation. heh, this is habit seen to many people that came to Perl from other programming language like C/C++ where a string should always be limited by double quotes, but many other languages (and Perl is one of them) offer extended functionality through these semantic sugarcubes :)
e.g.:
"." -> '.'
"*END*" -> '*END*'
"support\@mydomain.com" -> 'support@mydomain.com'
... etc ...

- check Perl FAQ for a perlish way of getting your hostname
- i'd rather consider using getpwuid and a caching system instead of pushing all users information into memory
- run this script on a cron basis scanning user writeable filesystems and you'll soon get headaches (considering of course that users are always b.a.d.) - they could create a heck lotta dumb files to make your script trash your system (heh, my first thought was to tell you to switch to a more efficient storage method for the %files data structure)
- presuming a MB equals '1000000' is wrong. indeed, HDD manufacturers inherited this darn habit, but this is not true on the filesystem thay lies onto that storage space ;-)
- you waste again a lots of CPU cycles performing a lot of useless stats: file used in your wanted routine as $_ has already been stat-ed by the File::Find module, so now you can rely on the information in _;
- as a principle: restrict the context of each variable as much as possible to avoid problems ;-] (i'm talking about most of the variables on this line: my ($uid, %files, $size, @pw, %unames, $str);)
 
Here is a trimmed down code that implements that cache I told you above, eliminates all useless stats and switches %files to hash of arrays ;-]
use Data::Dumper; use Cache::MemoryCache (); my $cache = new Cache::MemoryCache; find({wanted => \&ab_wanted, no_chdir => 1}, $opt{d}); print Dumper \%files; sub ab_wanted { if (-r _ && -f _){ my $size = int ((-s _) / 2**20); if ($size > $opt{s} && $opt{a} < -A _){ my $uid = (lstat(_))[4]; my $name = $cache->get($uid); unless (defined $name) { $name = getpwuid($uid); $cache->set($uid, $name); } push @{$files{$name}}, [ $_, $size, int -A _ ]; } } }
--
AltBlue.

In reply to Re: oldfiles by AltBlue
in thread oldfiles by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.