> -----Original Message-----
> From: Michael Fowler [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 2:48 PM
> To: Bob Showalter
> Cc: [EMAIL PROTECTED]
> Subject: Re: File Handling question - easy
>
>
> On Thu, Aug 02, 2001 at 02:31:28PM -0400, Bob Showalter wrote:
> > P.S. I'm surprised this works with while(). I didn't
> realize fileglobs
> > were magical inside while(), but it appears they are... Is
> this documented?
>
> Yes, perldoc perlop, in the I/O Operators section (5.6.1 version):
>
> A (file)glob evaluates its (embedded) argument only when it is
> starting a new list. All values must be read before it
> will start
> over. In list context, this isn't important because
> you automatically
> get them all anyway. However, in scalar context the
> operator returns
> the next value each time it's called, or "undef" when
> the list has run
> out. As with filehandle reads, an automatic "defined"
> is generated
> when the glob occurs in the test part of a "while",
> because legal glob
> returns (e.g. a file called 0) would otherwise
> terminate the loop.
> Again, "undef" is returned only once.
Thanks for the cite.
I played around with this a bit and found that:
perl -e 'print scalar(glob("*")) for (1..2)'
prints two different files, while
perl -e 'print scalar(glob("*")), scalar(glob("*"))'
prints the same file twice. I tried this on 5.005_03 and 5.6.1.
Wonder why? Seems like its related to the loop context and not merely
to scalar context.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]