in reply to Interpolation: when it occurs? another beginner question..
These interpolate:
"$var"qq{$var}
These do not:
'$var'q{$var}
TL;DR: if you want interpolation, don't use single quotes!
OK, I see what you're asking. You want delayed evaluation - I'll update with a solution to that momentarily!
Update: OK, how about this...
use v5.10; use strict; use warnings; sub delayed (&) { package delayed; use overload q[""] => sub { $_[0]->() }, fallback => 1; bless shift; } my $string = delayed {"Look $::person, no $::thing!"}; $::person = "Ma"; $::thing = "stringy eval"; say $string;
Update II (about a week later): I've released String::Interpolate::Delayed using some of the ideas explored in this thread.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Interpolation: when it occurs? another beginner question..
by karlgoethebier (Abbot) on Feb 25, 2013 at 15:26 UTC | |
by tobyink (Canon) on Feb 25, 2013 at 16:04 UTC | |
by karlgoethebier (Abbot) on Feb 25, 2013 at 18:48 UTC | |
by Discipulus (Canon) on Feb 25, 2013 at 20:45 UTC |
In Section
Seekers of Perl Wisdom