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;
|
|---|