SPUG: interesting while() behavior and hosting recs

Tim Maher tim at consultix-inc.com
Fri Oct 1 12:46:36 CDT 2004


On Fri, Oct 01, 2004 at 08:25:02AM -0700, DeRykus, Charles E wrote:
> 
> 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 (;;).
> Charles DeRykus

I've been skimming this thread, but having trouble with
a fundamental element of the discussion. 

Specifically, what qualifies

	while () { statement; }

as having /anything/ to do with the conceptually understandable
(albeit technically non-existent) "list in scalar context"?

Or, for that matter, the parens in while's close relative:

	if () { statement; }

AFAIK, those parens after the keywords are *required elements of
syntax* that have nothing to do with the kind of "list formation"
effect that people associate with expressions like:
	@stuff=(1,2,3);
and
	@stuff=();	# empty list

It seems to me that earlier posts are equating the parens in
"while ()..." to those in my empty list example above, which
conflicts with my interpretation that they are merely
syntactic elements after "while".

If they're /not/ syntactic, why can't we write code like this?
	while $foo { statement; }
	while @foo { statement; }
or
	if 1 { statement; }

(And that code doesn't compile; I checked!)

I'll readily admit that I, like many JAPHs, have some of my own
ways of thinking about Perl that make it easier for me to use, and
to teach, and that usually serve me quite well -- despite their
technically being over-simplifications of Perl's (twisted)
reality. 8-}

As a case in point, I offer the widespread notion that parens
function as "list constructors" in expressions like
"@array=(1,2)" and "print (1,2)", which is tremendously useful,
despite being less than a perfectly accurate representation of
how those expressions are actually parsed and evaluated, IIRC.
(What's the real story? Is it that the comma operator in list
context returns all the expressions, so the parens are just there
for reasons of precedence in the case of an assignment?)

Surely, even in Perl, there are some elements of basic syntax
that can be trusted to have concrete meanings -- like while's
parens; aren't there? 8-}

*--------------------------------------------------------------------------*
| Tim Maher, CEO     (206) 781-UNIX      (866) DOC-PERL     (866) DOC-UNIX |
| tim(AT)Consultix-Inc.Com  http://TeachMePerl.Com  http://TeachMeUnix.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
| Watch for my upcoming book: "Minimal Perl for Shell Users & Programmers" |
| Classes! 10/4: UNIX Fundamentals  11/30: Perl  12/6: Shell & Utilities   |
*--------------------------------------------------------------------------*


More information about the spug-list mailing list