I'm using glob in case the absolute path names contain a space character somewhere.

How does glob help you with path names that have spaces? glob accepts a file spec (i.e. something with *) and returns all matching files. It's used to allow the user to specify multiple files at once. However, since you're only interested in one file, it makes no sense to accept file specs or to use glob.

-f works with spaces, whether you've passed the value through glob or not.

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?"

When glob is called in a scalar context, it still returns all the values it would in a list context. It just returns one by one. Somehow, it has to tell you when it's done returning all the values. It does that by returning undef.

The first time you call glob, it returns the first filename that matches the file spec.

The second time you call glob, it returns undef since there are are no files that match the file spec passed to the first call to glob.


In reply to Re^3: Using File::DosGlob::glob in loop only works first time by ikegami
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.