Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 lurking in the Monastery: (3)
As of 2020-02-24 00:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (104 votes). Check out past polls.

    Notices?