in reply to Re: Perl ignore arrow object operator in search/replace (s/searchregex/replacestring/)
in thread Perl ignore arrow object operator in search/replace
That's wrong! Variable interpolation does easily dereference hashes and arrays (i.e. within strings and substitutes).
DB<114> $h={a=>42} => { a => 42 } DB<115> "$h->{a}" => 42
Though coderefs seem to be excluded.
DB<118> $sub=sub { "nope" } => sub { "???" } DB<119> "$sub->()" => "CODE(0xa5cc200)->()"
But the @{[...]} ("local eval") trick always helps where a general /e would cause too much harm.
DB<120> $_="X" => "X" DB<121> s/X/@{[ $sub->() ]}/ => 1 DB<122> $_ => "nope"
see also: s/RegEx/substitutions/: Variable interpolation and when to use /e - modifiers
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl ignore arrow object operator in search/replace (s/searchregex/replacestring/)
by tobyink (Canon) on Feb 17, 2014 at 20:06 UTC | |
by LanX (Saint) on Feb 17, 2014 at 20:16 UTC | |
by tobyink (Canon) on Feb 17, 2014 at 21:11 UTC | |
by Anonymous Monk on Feb 18, 2014 at 00:38 UTC |