Very interesting. I created the following package:
package Scrap::Foo; use strict; sub bar { my $dummy; $dummy->{_init}->{__PACKAGE__}++; return $dummy; } 1
And my test code:
use strict; use Scrap::Foo; use Data::Dumper; my $dummy = Scrap::Foo::bar(); print Dumper $dummy;
Generated this output:
$VAR1 = { '_init' => { '__PACKAGE__' => '1' } };
And the fix:
my $package = __PACKAGE__; $dummy->{_init}->{$package}++;
Thanks for the info. Now who wants to tell Damian? :)
Cheers,
Ovid
Update: japhy's unary fix is not only shorter, but it should be faster as it doesn't involve creating a variable for no other reason than throwing it away.
Vote for paco!
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re(2): Syntax for preventing repeat object initializations
by Ovid
in thread Syntax for preventing repeat object initializations
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |