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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |