Perl's interpolation rules state that arrays ("@foo"
) and scalars ("$bar"
), as well as (a) lookups of values in hashes ("$baz{bar}"
) or arrays ("$foo[1]"
), and (b) dereferences of the previous cases ("@$foo, $$bar, $baz->{bar}, $foo->[1]"
) are interpolated into double quoted strings.
Function calls, and per extension method calls, are not interpolated.
You can interpolate arbitrary code into strings by using a trick of dereferencing an anonymous reference. Usually, you want an arrayref:
"foo @{[ expressions; ]} bar"; # interpolating anon hashref
but scalar refs work as well (they are 1 character longer).
"foo ${\( expressions; )}" # interpolating anon scalar ref
However, you should consider caching the value you want to interpolate in a scalar variable:
my $cardNumber = $self->cardNumber;
for (@accountsInfo) {
if (/\A\Q$cardNumber\E/) {
$self->pushing(split /,/);
$self->invokeAccount();
}
}
Additional note: I stripped out unneccessary parens and mentions of $_
from that code snippet. Also, I escaped the characters in $cardNumber
so that they match literally, and aren't treated as a regex.