good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^3: Interpolation: when it occurs? another beginner question..by tobyink (Canon) |
on Feb 25, 2013 at 16:04 UTC ( [id://1020538]=note: print w/replies, xml ) | Need Help?? |
For what it's worth, it does also work with lexical variables, but you need to declare them up-front...
Here's a version that eliminates the need to declare variables up-front, but does the interpolation manually using s///eg. It's pretty dodgy, and I wouldn't put it anywhere near production code, but it's quite cute as an example...
It's cute, but the code that does the interpolation is pretty dodgy.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|