----- Original Message -----
From: "Michael R. Wolf" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
> >"Leon" <[EMAIL PROTECTED]> writes:
> > But my instinct tells me that what you were
> > trying to say is that with each iteration, the variable my
> > $b++ was resetted, hence no increment (remains as
>
> It may *appear* that way, but that's not *exactly* what's
> happening. What *is* happening is that every time you
> specify "my", you _create_ a new variable. (That has the
> effect of _resetting_ it, but there is no "reset" operation
> taking place.) That newly created variable (with a value of
> undef) is incremented (from 0 (the integer interpretation of
> undef)) to 1. At the end of the loop (at the close brace,
> actually) the variable is destroyed, reclaimed by memory,
> and no longer accessible.
>
> It's like having a new baby each iteration of the loop and
> then giving it a birthday party. At the end of the party,
> you'll always have a 1 year old baby. On the other hand, if
> you give birth to that baby outside the loop, then every
> time through the loop, you've got the same baby, and are
> therefore correct in relying on that baby getting older at
> every birthday party in the loop since it remembers its
> state (history) from the previous iteration.
>
> Births are expensive, but they *do* guarantee that you've
> got a brand, spankin' new object to work on. But in this
> case, you don't really want to go through all the expense
> and resources only to have it destroyed (I'd say "die", but
> that's another keyword) at the end. Skip the birth/death
> cycle. Have one birth only. It's a lot less traumatic on
> the parents (memory allocator) who have to provide the
> nutrients (RAM) and energy (CPU cycles) for it's creation
> (allocation). And then it dies once (and only once) when it
> hits its end of life, but that's *not* at the end of the
> loop, it's further down the program.
A great anology. This clears up everything ! Therefore, with each iteration
of a loop, it is a "birth of a new baby" and its happy&sad journey ends at
the "the curly Heavenly gates =>}".
In the course of studying, I also wish to let Members know the following:-
use strict;
my $number = 0;
OUTER : while ($number < 3){
$number++; # line 4
my $counter = $number;
my $number = 3;
$number = 10; # line 7; does not alter the value of line 4
# So Perl is pretty smart eh!
print '*'x35,"\n($counter).",
' OUTER lexically scoped $number is not',
" resetted by \$number = 10 in line 7 as can be seen
here.\n",
'*'x35,"\n";
INNER : while ($number < 15){
$number++;
print "INNER while \$number =
$number\n";#'&'x35,"\n";
};
};
Thanks Michael R. Wolf & Members.
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]