That said, I'm not sure why you're using glob at all if you only look at the first element. Why not just do unless ( -f $template_file )?

I have a list of files that I want to ensure are actually files (the user will be feeding in filenames via a configuration file and I don't want the program to go further if said file(s) don't exist). I'm using glob in case the absolute path names contain a space character somewhere.

The thing that's bothering me about this is "Why does glob give me a valid answer for the first item in my list, even when I'm using it in scalar context, and not the second?" Is it set in stone somehow, like m/$abc/o is set to only optimize the first interpretation you ask of it? Because in my example, when I use a different instance of glob (i.e. the second foreach loop/block) against the "second" filename, it kicks it out just fine (and then fails on the "previously okay" first value). In DWIM-land, I'd think that each invocation of glob, even within a foreach loop, would be independent of the last.

Though as I said before, I can move ahead with answers that work, and the slice/[0] suggestion works. :-)


In reply to Re^2: Using File::DosGlob::glob in loop only works first time by ff
in thread Using File::DosGlob::glob in loop only works first time by ff

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.