in reply to Re^2: In place search and replace with a hash
in thread In place search and replace with a hash

You're so addicted to Perl you can't forget it even in a disco :)

It works with strings too :)

use 5.020; use warnings; my %h = ( foo => 1, bar => 2 ); $_ = 'foobar'; s/(foo)/$h{'$1'}/; say $_; $_ = 'foobar'; s/(foo)/$h{$1}/; say $_; my $foo = 'foo'; say "$h{'$foo'}bar";
output:
Use of uninitialized value $h{"$1"} in substitution iterator at extr.p +l line 7. bar 1bar Use of uninitialized value $h{"$foo"} in concatenation (.) or string a +t extr.pl line 15. bar

Replies are listed 'Best First'.
Re^4: In place search and replace with a hash
by LanX (Saint) on Dec 28, 2014 at 03:08 UTC
    OK I understand now what's happening, thanks! :)

    The interpolation is done by translating to a concat which is executed.

    (parsing hell)

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    update

    see update in this post for an explanation of how interpolation works.