Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: In place search and replace with a hash

by AnomalousMonk (Archbishop)
on Dec 28, 2014 at 04:10 UTC ( [id://1111524]=note: print w/replies, xml ) Need Help??


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

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:   <%-(-(-(-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1111524]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found