I don't understand what glob does here



I don't understand the behavior of the following...

$ touch "file"
$ perl -e 'foreach $num (0 .. 4) { print "$num .. "; print (scalar glob("file")); print " "; print (scalar glob("file")); { print " ok\n"; } }'
0 .. file file ok
1 .. ok
2 .. file file ok
3 .. ok
4 .. file file ok

I thought that if I were to get "undef" returned on the second scalar
invocation, I would have seen one "file" in each iteration, not 2
successful followed by 2 unsuccessful.

Why does the behavior change between iterations of the foreach loop
here? I've read through glob and File::Glob and I haven't seen anything
that appears to explain this.

Thanks.

--
Darren Dunham ddunham@xxxxxxxx
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
.



Relevant Pages

  • Re: A directory "grep" in RUBY?
    ... # the use passes in a string value representing a glob. ... # an array with all of the matching files, ... # iteration starts ... wanted the regex ...
    (comp.lang.ruby)
  • Re: increasing counter whithin loop?
    ... > the loop? ... there's nothing preventing you from doing e.g.: ... # set skip to true to skip the next iteration ... Prev by Date: ...
    (comp.lang.ruby)
  • Re: I dont understand what glob does here
    ... > invocation, I would have seen one "file" in each iteration, not 2 ... Each individual glob() call maintains its own state. ... The first time ... through the for loop is the first call to globfor each glob ...
    (comp.lang.perl.misc)
  • Re: .NET Socket
    ... Rahul Anand wrote: ... > But later I noticed that if in last iteration the bytes come to be less than ... can call Socket.Shutdown in another thread to interrupt that blocking call. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strange query problem php/mysql
    ... iteration its contents are unpredictable. ... Fix this first. ... chars. ... Prev by Date: ...
    (comp.lang.php)