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

Hi AnomalousMonk, thanks for your reply. I probably should have specified that I'm pretty new to perl. Could you comment at all at what your code does?
  • Comment on Re^4: In place search and replace with a hash

Replies are listed 'Best First'.
Re^5: In place search and replace with a hash
by AnomalousMonk (Archbishop) on Dec 28, 2014 at 04:10 UTC

    The code example above was meant as a counter-example to what I understood LanX to be saying. Comments:

    my %hash = ('$1' => 'oops', 'abc' => 'ok'); # create a hash 'abc' =~ m{ (abc) }xms; # capture a sub-string to $1 print qq{captured '$1'}; # show what that string is print $hash{'$1'}; # show effect of single-quotes: no interpolation
    Had  $1 been used directly (as in $hash{ $1 }), the output would have been 'ok'. A more complete example:
    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my %hash = ('$1' => 'oops', 'abc' => 'ok'); dd \%hash; ;; 'abc' =~ m{ (abc) }xms; print qq{captured '$1'}; ;; print 'single-quoted: ', $hash{'$1'}; print 'straight: ', $hash{ $1 }; " { "\$1" => "oops", "abc" => "ok" } captured 'abc' single-quoted: oops straight: ok


    Give a man a fish:   <%-(-(-(-<