On Jul 21, Bob Showalter said:
>Uh-uh. $_ and foreach iterators don't behave that way, nor should they. Look
>at what $_ is doing in that example. $1 is doing the same thing.
His examples don't show what you're talking about, and you didn't provide
any examples yourself. You can't iterate over a list of values for $1 to
get assigned to it, like you can with $_ or any other foreach iterator.
Here's the problem. The $DIGIT variables are localized to a block, but
they're done so in a manner that I don't think you can achieve in Perl,
without adding an additional block to code:
($s = "a") =~ /(.)/;
for (0 .. 2) {
print "$1.";
(++$s) =~ /(.)/;
}
This code prints "a.b.c.". One might argue that $1 should be "a" at the
start of EACH iteration of the block, but this is not the case. But we
can't make local()ized values persist like that:
$x = ($s = 10);
for (0 .. 2) {
print "$x.";
local $x = ++$s;
}
This prints "10.10.10.", as it should. If we wanted it to print
"10.11.12.", we'd need to do more work:
{
$x = ($s = 10);
local $x = $x;
for (0 .. 2) {
print "$x.";
$x = ++$s;
}
}
This prints "10.11.12.", but we had to move the localization outside the
loop. The localization of the $DIGIT variables is implicit, and seems to
be moved to JUST OUTSIDE the block.
This is the issue. Why are the $DIGIT variables bound to the block
they're in IN TOTALITY, rather than for the life of the execution of the
block?
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]