Scope of variables in a function
James Laver
james.laver at gmail.com
Sun Jun 2 12:53:10 BST 2013
On 2 Jun 2013, at 12:42, Dave Mitchell <davem at iabyn.com> wrote:
> I'm not aware of any particular performance penalty:
>
> $ time perl5180o -E'for (1..100_000_000) { my $x = 1 }'
>
> real 0m5.638s
>
> $ time perl5180o -E'for (1..100_000_000) { my $x }'
>
> real 0m4.012s
>
> $ time perl5180o -E'for (1..100_000_000) { state $x = 1 }'
>
> real 0m3.060s
>
> $ time perl5180o -E'my $x; for (1..100_000_000) { $x }'
>
> real 0m2.787s
>
> Yes technically its slightly slower than a bare '$x', but it's a lot
> faster than a bare 'my $x';
I stand corrected. I thought I'd seen a warning in the docs at some point but evidently I'm making it up.
/j
More information about the london.pm
mailing list