|XP is just a number|
'my' and 'state' declaration inside a loopby nemesisgus (Acolyte)
|on Aug 05, 2012 at 01:26 UTC||Need Help??|
nemesisgus has asked for the
wisdom of the Perl Monks concerning the following question:
After reading this old but interesting thread: About "state" variables in Perl 5.10, it came to my mind if there is any difference in performance between this:
given that, afaik, if we rewrite the second example using 'my', it does have an extra cost at runtime, since it is run once each time execution passes the 'my' declaration:
Is this "extra" time cost also present in the case of declaring the variable with 'state' although the variable is not reinitialized each time?
Thanks and sorry for the silly question.PS: I know the second example generates a different output, but I'm mostly interested in the performance effect.