in reply to multiple dir. grep

Something like
@files = sort grep -f, map {opendir DIR, $_; readdir DIR} @dirlist;
? That's a little quick and dirty, since I don't closedir at all, and I don't check the return value of opendir. But it is kind of slick.

If perl had an operator (call it <,) that would execute both sides (left-to-right) and return the left side, then I could neatly do the map as

map { opendir DIR, $_; readdir DIR <, closedir DIR }
I think that would come in handy reasonably often.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: multiple dir. grep
by BrowserUk (Patriarch) on Apr 06, 2005 at 15:02 UTC
    That's a little quick and dirty, since I don't closedir at all,

    Use a lexical dirhandle and perl will close it for you.

    perl -le"print for sort grep!/^\.\.?/, map{ opendir my($DIR), $_; rea +ddir $DIR } map glob, @ARGV" ./*

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco.
    Rule 1 has a caveat! -- Who broke the cabal?
Re^2: multiple dir. grep
by tlm (Prior) on Apr 06, 2005 at 14:16 UTC

    That's what the ol'

    select((select FH, $|=1)[0]);
    business is all about, so you could do
    map { open DIR, $_; @{ ( [ readdir DIR ], close DIR )[ 0 ] } } @dirli +st;
    Hmmm... Not exactly perspicuous.

    the lowliest monk