The following tests were done on Solaris, using just the standard 'glob' as opposed to DosGlob.

First, my directories

> ls -1 abc.txt def.txt xyz.boo
Now, use glob in scalar context, and it is apparent that it buffers it's output, to be sent back one at a time, regardless if it is called again with a new parameter.
> perl -e '@a=qw(*.txt xyz.boo);foreach $f (@a) {print "$f->";$y=glob( +$f);print $y,"\n";}' *.txt->abc.txt xyz.boo->def.txt
Do the same thing in list mode, and the list is 'refreshed' when a new glob is called.
> perl -e '@a=qw(*.txt xyz.boo);foreach $f (@a) {print "$f->";($y)=glo +b($f);print $y,"\n";}' *.txt->abc.txt xyz.boo->xyz.boo
That said, you don't really need to use glob unless you use wildcards.

I got bit once because I mistakenly believed that glob would always return files that only matched the inputs (with or without wildcards). In other words, the following is only true IF you use wildcards.

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

If there are no wildcards in the parameter passed to glob, glob will simply return the string, even if the file does not exist. Notice that 'boo.txt' is not a valid file.
> ls -1 abc.txt def.txt xyz.boo > perl -e '($y)=glob("*.txt");print $y,"\n";' abc.txt > perl -e '($y)=glob("boo.txt");print $y,"\n";' boo.txt

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