Hi Monks,
I'm perplexed about the workings of File::DosGlob.

In the Windows folder in which this Perl program lives there are two files. Their names here are simple but in the real program I need to allow for spaces to exist in the filenames. My problem arises in that, within a loop, when I use File::DosGlob::glob to generate a filename, the '-f' test I do against the file only works on the first file in the list of files I'm testing. When I reverse the order of the files I test, it again approves of the first in the list but balks at the second.

And to point out the obvious, when I run the glob in a different statement block, it happily accepts a filename that it previously just rejected.

Any ideas of what's happening? Thanks.

use strict; use File::DosGlob 'glob'; my @files_to_check = ( 'file_a.txt', 'file_b.txt' ); FILE_IN_ALPHA_ORDER: foreach my $template_file ( sort @files_to_check ) { # The next three lines are for peeking at $template_file warn "ftf2: '$template_file'\n"; my $template_file_t2 = qq{"$template_file"}; warn "ftf2a: '$template_file_t2'\n"; unless ( -f ( File::DosGlob::glob qq{"$template_file"} ) ) { warn "8251b: File check, cannot access '$template_file', $!\n\ +n"; next FILE_IN_ALPHA_ORDER; } warn "ftf2b: '$template_file' is okay.\n\n"; } warn "\n"; FILE_IN_REVERSE_ORDER: foreach my $template_file ( reverse sort @files_to_check ) { # The next three lines are for peeking at $template_file warn "ftf3: '$template_file'\n"; my $template_file_t2 = qq{"$template_file"}; warn "ftf3a: '$template_file_t2'\n"; unless ( -f ( File::DosGlob::glob qq{"$template_file"} ) ) { warn "8251b: File check, cannot access '$template_file', $!\n\ +n"; next FILE_IN_REVERSE_ORDER; } warn "ftf2b: '$template_file' is okay.\n\n"; } __END__ Results look like: ftf2: 'file_a.txt' ftf2a: '"file_a.txt"' ftf2b: 'file_a.txt' is okay. ftf2: 'file_b.txt' ftf2a: '"file_b.txt"' 8251b: File check, cannot access 'file_b.txt', No such file or directo +ry ftf3: 'file_b.txt' ftf3a: '"file_b.txt"' ftf2b: 'file_b.txt' is okay. ftf3: 'file_a.txt' ftf3a: '"file_a.txt"' 8251b: File check, cannot access 'file_a.txt', No such file or directo +ry

In reply to 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.