[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] "," instead of ";" in "for"



On Sat, 28 Aug 1999 03:11:46 +1000, Peta Adams - John Murray wrote:

>Anyway, I did some testing [got a bit long winded] but any further comment
>would be sincerely appreciated.
>
>for (X){
> print 'looped a time',"\n";
>}
>OUTPUT:
>Y

Ok, here's one comment. It has the great feature of running the loop
ONCE (always), but with the loops variable as an ALIAS to the original
scalar, so, effectively, it is a "with" statement:

	$\ = "\n";
	$x = "before";
	for my $y ($x) {
		print "Run once!";
		$y = "changed!";
	}
	print $x;
->
Run once!
changed!

$x needn't be a simple variable. If the scalar is a really complex
value, e.g. a dereference through many stages, and you drop the optional
loop variable (here $y), you can simply access (read/write) the scalar
through $_.

Imagine the "for" as meaning "with". The only difference with a real
"with" syntax structure is that "last" inside it, still recognizes this
loop as a loop. In a real "with" statement, this wouldn't be the case, I
guess.

-- 
	Bart.

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org