Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

RE: RE: Re: Perlmonks Code Proxy

by Boogman (Scribe)
on Aug 19, 2000 at 01:24 UTC ( #28599=note: print w/ replies, xml ) Need Help??


in reply to (Ovid) RE(2): Perlmonks Code Proxy
in thread Perlmonks Code Proxy

The /e causes the right hand side of s/// to be handled as code to eval. Well, since we are deliberately matching Perl code with this regex, this solution tends to choke quite spectacularly.
Hmmm... Thats strange. I decided to fool around with it and tried this out:
my $i = 1; my $string = 'print "hello";'; my $content = 'print "hello";$x + 2; print "hello";print "hello";print + "hello";'; $content =~ s/($string)/$1.$i++."\n"/ge; print "$content\n"; eval $string;
and it printed out
print "hello";1 $x + 2; print "hello";2 print "hello";3 print "hello";4 hello
It doesn't seem that it executed the print statement that was matched, even though if we hand the string directly to exec, it does print out hello.


Comment on RE: RE: Re: Perlmonks Code Proxy
Select or Download Code
RE (tilly) 4: Perlmonks Code Proxy
by tilly (Archbishop) on Aug 19, 2000 at 01:28 UTC
    Right hand side, not left:
    $str = "Hello world\n"; $str =~ s/o/print "Got an o!\n"/eg; print $str;
      yeah - I was saying that if you matched code on the right side, and then used that code in the eval expression with $1, it wouldnot get executed.

      AKA, saying s/(stuff)/$1/eg would not do anything even if the stuff captured in $1 was perl code.

      $string = "print 'got an o\n'"; $string =~ s/(.*)/$1/eg;
      Doesn't print anything.
        OK, I misunderstood what you were trying to figure out.

        Even so ehis should not be a surprise. Execute the statement $var and nothing happens except that the contents of $var are returned. Same thing with $1. Execute it and it returns the contents of $1 as a string, presumably to be placed back in the original string.

        But try using the modifier /eeg and see what that does. :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-10-23 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls