in reply to Using File::DosGlob::glob in loop only works first time
First, my directories
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.> ls -1 abc.txt def.txt xyz.boo
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=glob( +$f);print $y,"\n";}' *.txt->abc.txt xyz.boo->def.txt
That said, you don't really need to use glob unless you use wildcards.> 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
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
|
|---|