|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Re: Best Practice for replace subby tobyink (Prior) |
| on Mar 01, 2013 at 12:17 UTC ( #1021235=note: print w/ replies, xml ) | Need Help?? |
|
Perl 5.10 and above have state variables, but they don't work for hashes and arrays - just scalars. Still, you can use hashrefs/arrayrefs.
If you need to support older versions of Perl, then curly braces can be used to limit the scope of lexical variables...
Or even better (because it delays populating the variables until they're needed):
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||