Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

s/RegEx/substitutions/: Variable interpolation and when to use /e - modifiers

by LanX (Canon)
on Dec 04, 2012 at 18:58 UTC ( #1007141=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      DB<1> $_='abc'; s/a(b)c/$1/; print $_
    b
      DB<2> $_='abc'; s/a(b)c/$1/e; print $_
    b
    
  2. or download this
      DB<1> $_='abc'; s/a(b)c/$1/; print $_
    b
      DB<3> $_='abc'; m/a(b)c/; $_ = "$1" ; print $_
    b
    
  3. or download this
      DB<2> $_='abc'; s/a(b)c/$1/e; print $_
    b
      DB<4> $_='abc'; m/a(b)c/; $_= eval '$1'; print $_
    b
    
  4. or download this
      DB<5> $_='warn 666'; s/(.*)/$1/e; print $_
    warn 666
      DB<6> $_='warn 666'; m/(.*)/; $_= eval '$1'; print $_
    warn 666
    
  5. or download this
     
      DB<7> $_='warn 666'; s/(.*)/$1/ee; print $_
    666 at (eval 171) ....    # skipped error message
    ...
      DB<8> $_='warn 666'; m/(.*)/; $_= eval eval '$1';  print $_
    666 at (eval 175). ... # skipped error message
    1      # $_ = return code from warn
    
  6. or download this
      DB<134> $hash{b}=666;
     
    ...
    666
      DB<136> $_='abc'; m/a(b)c/; print "$hash{$1}";
    666
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-07-29 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls