SPUG: interesting while() behavior and hosting recs

DeRykus, Charles E charles.e.derykus at boeing.com
Fri Oct 1 10:25:02 CDT 2004


Yes, you're right, there's no "list in scalar context" but I always
had trouble with just the "semantic denial". The point to me is more
what Perl does with something that looks like a "list in scalar context"
and there's no general rule about what will happen. No termination, no 
warning, etc.  It's parsed and the fact that  its appearance is of a 
"list in scalar context" provides a way to identify the beast and its 
effects.  

Also the faq you've cited, simply documents the fact that it can act like
the comma operator:

   
     As a side note, there's no such thing as a list in scalar
     context.  When you say

     $scalar = (2, 5, 7, 9);

     you're using the comma operator in scalar context so it uses the scalar
     comma operator.There was no list at all!  This causes the last value to 
     be returned: 9., 

But, as we've seen Joel's post, the effects of a "list in scalar context" in
a different may altogether different and unexpected... ie, while () ...
gets parsed as for (;;).

Cheers,
--
Charles DeRykus




     




-----Original Message-----
From: John W. Krahn [mailto:krahnj at telus.net] 
Sent: Thursday, September 30, 2004 10:00 PM
To: SPUG
Subject: Re: SPUG: interesting while() behavior and hosting recs


DeRykus, Charles E wrote:
> An array (AV) can meaningfully be evaluated in scalar context so I'd 
> expect @empty to fail. However, () is a list in scalar context

As Randal has pointed out many times and as the FAQ clearly states:

perldoc -q "What is the difference between a list and an array" [snip]
        As a side note, there's no such thing as a list in scalar context.


> which doesn't behave in a predictable manner.

That is because it doesn't exist.

In the expression:

while () { ... }

there is NO list.

As a side note, and has been recently discused on comp.lang.perl.misc, 
parentheses do not create a list.

http://groups.google.com/groups?threadm=UjE6d.138341%24D%25.46143%40attbi_s51



John
-- 
use Perl;
program
fulfillment _____________________________________________________________
Seattle Perl Users Group Mailing List  
POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays, Location Unknown
WEB PAGE: http://www.seattleperl.org



More information about the spug-list mailing list