Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: File::find hack

by oko1 (Deacon)
on Feb 25, 2012 at 16:55 UTC ( #956137=note: print w/replies, xml ) Need Help??

in reply to File::find hack

Not especially elegant - I only strive for grace, not necessarily achieve it :) - but here's something that I think is a bit cleaner and more direct:

#!/usr/bin/perl use common::sense; use File::Find; my $dir = "/some/dir/some/where"; my %dirs; finddepth(\&newest, $dir); sub newest { return unless -f; my ($d, $n) = ($File::Find::dir, $File::Find::name); $dirs{$d} ||= $n and return; $dirs{$d} = $n if (stat($n))[9] > (stat($dirs{$d}))[9]; } print "$_: $dirs{$_}\n" for keys %dirs;
I hate storms, but calms undermine my spirits.
 -- Bernard Moitessier, "The Long Way"

Replies are listed 'Best First'.
Re^2: File::find hack
by nemesdani (Friar) on Feb 25, 2012 at 17:46 UTC
    Cool! Thank you very much! Had to think for awhile what ||= does, I'm not an expert as you can clearly see...:)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://956137]
[Corion]: choroba: :-D
[Corion]: And yes, at least the basic implementation is to strip off some prepositions ("the", "a", "an") from the term with regular expressions and then do a regex match ;-)
[Corion]: So that could become a fun series of articles that implement this with regular expressions, Parse::Eyapp, Marpa, YACC, Perl6 and Regexp::Grammar and whatnot. If I have a test suite, I could even do benchmarks.
[Corion]: I guess part of the fun will be to add all those optional prepositions etc. to the grammar, whereas that is easy with regular expressions :)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-08-17 11:36 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (286 votes). Check out past polls.