in reply to Re: 'my' and 'state' declaration inside a loop
in thread 'my' and 'state' declaration inside a loop
Thank you both for your wisdom.
I read the my and state docs before asking but I couldn't find an answer.
I understand that state was introduced as an improvement to my and that they have different purposes although they are overlapping in some cases and can be used to reach the same effect.
My question was basically conceptual.
Anyway, just if somebody is interested, it seems that there is, of course, a difference:
my $n; for (1..100000000) { $n=0 } real 0m9.395s user 0m9.397s sys 0m0.000s _________________________________ for (1..100000000) { my $n=0 } real 0m12.773s user 0m12.765s sys 0m0.004s _________________________________ for (1..100000000) { state $n=0 } real 0m7.282s user 0m7.244s sys 0m0.008s
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 'my' and 'state' declaration inside a loop
by GrandFather (Saint) on Aug 07, 2012 at 20:32 UTC |