Am Montag, 23. Mai 2005 06.54 schrieb Wijaya Edward:
> That's very clever John,
> I'm wondering why ($cnt++) won't work instead of this
>
> > recursive(++$cnt) if $cnt<10;
>
> I tested it, it gave endless recursion.

Yes, spontaneosly I used $cnt++ first, too :-)

++$cnt is called "pre increment" - in contrast to $cnt++ ("post increment") - 
and means that $cnt is incremented _before_ the incremented value is used.

So, 

 recursive(++$cnt);

first increments $cnt and then passes it to recursive().

 recursive($cnt++);

always passes the same value to recursive() and increments it afterwards (but 
this incremented value is never used).

see (from cmd line)

 perldoc perlop

>
> And what's the meaning of "0" here?
> Why didn't you pass "1"  as for recursive(1),
> which is more sensible to me? Which also works.
>
> > recursive(0);
I tend to count levels from 0, not 1, that's all.


regards, joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to