Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
The stupid question is the question not asked
 
PerlMonks  

Re: Using File::DosGlob::glob in loop only works first time

by Sandy (Curate)
on Feb 24, 2006 at 21:12 UTC ( [id://532722]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Using File::DosGlob::glob in loop only works first time

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://532722]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.