in reply to Backreference woes

I think your immediate problem is not to do with regular expression matching or shell escape. Your immediate problem is because you are trying to replace the matching pattern with '$1' as an exact string, not as a back reference. Try this instead...

#!/usr/bin/perl -w my $searchExp = $ARGV[0]; my $replaceExp = $ARGV[1]; my $textIn = <STDIN>; my $count = 0; # Do the replacing eval "\$count = (\$textIn =~ s/$searchExp/$replaceExp/go)"; if ($count > 0) { print $textIn; } exit;
And the output is exactly as expected...
>> echo 'JHTML `Java in here` code' | perl p11.pl '`(.*)`' '<%=$1%>' JHTML <%=Java in here%> code

Replies are listed 'Best First'.
Re: Re: Backreference woes
by bemfica (Initiate) on Jan 02, 2004 at 04:44 UTC
    Yes, that does it! Thank you very much for the help, it is much appreciated.

    A.