Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: eval problem

by bv (Friar)
on Dec 04, 2009 at 04:25 UTC ( #811011=note: print w/replies, xml ) Need Help??


in reply to eval problem

I'm sure you've gotten all the info you needed about eval, but if you use lookaheads, you could make this work without needing to specify captures (with parentheses) in your $pattern. (I'm assuming you don't want to define $repl based on user input, but it could be made to work that way too)

#untested, but should work my $str = 'abcd'; my $pattern = shift; if ($str =~ $pattern) { my $repl = shift; say '$repl: ', $repl; say 'old $str: ', $str; $str =~ s/(?=$pattern)/$repl/; say 'new $str: ', $str; } __END__ $ perl 2perl.pl 'ab' '--' $repl: -- old $str: abcd new $str: --abcd

@_=qw; Just another Perl hacker,; ;$_=q=print "@_"= and eval;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-12-08 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?