in reply to Re: Syntax for preventing repeat object initializations
in thread Syntax for preventing repeat object initializations
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid) Re(2): Syntax for preventing repeat object initializations
by japhy (Canon) on Jul 17, 2001 at 04:18 UTC | |
by MeowChow (Vicar) on Jul 17, 2001 at 05:37 UTC |