merlyns's comment is on the button. Becuase I am in hard core work avoidance mode, though, I will offer some suggestions

Most of these snippets will assume the list of filenames is in ( imagine this ) @filenames. I will state other assumptions later

If you don't care to preserve the filenames, this one is kinda neat. It is compact and has the convenient side effect of giving you the name of the file that first matched.

shift @filenames while ( @filenames && ! -e $filenames[0] ); die "No names matched" unless ( @filenames );

If you must preserve the data, you will likely want a foreach loop. This loop will also preserve any match. It is also a bit more verbose than the previous example.

my $found = ''; foreach ( @filenames ) { next unless -e $_; $found = $_; last; }
These will give you better average case performance than either of the two methods you mentioned in your question. The grep-map combo is really nasty - it will walk through the entire list twice even if the first file in the list exists.

Mik mikfire


In reply to Re: Seeking multiple defined files by mikfire
in thread Seeking multiple defined files by DaWolf

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.