in reply to Re: can't get $& to remove value in a substitution
in thread can't get $& to remove value in a substitution

thanks for your input monks, it's much appreciated :)
i've discovered the problem...
the actual match i was trying to replace has parentheses within it, which is buggering up the process.

if i try and replace:
 $content = qq(<textarea class="FolderTxtArea" name="blah"><%=foo::doSomething %></textarea>);

it works.
however, if i try:
 $content = qq(<textarea class="FolderTxtArea" name="blah"><%=foo::doSomething ()%></textarea>);# note the parentheses after doSomething

it fails.

now i have to figure out a good way to escape the parentheses inside a variable.
i could just go in and temporarily replace them, which seems like a bit of a hack
if anyone is aware of a more elegant way of doing this i'd love to hear it.
once again, my thanks for your help

p.s. one lesson here is to copy and paste code verbatim for others to try. my apologies
only reason i didn't was for readability- the string i was trying to replace is awful long and ugly looking :)

Replies are listed 'Best First'.
Re: Re: Re: can't get $& to remove value in a substitution
by roik (Scribe) on Oct 24, 2002 at 14:31 UTC
    This is from the perlre manpage. I've not used it before so this is a first stab:
    \Q quote (disable) pattern metacharacters till \E
    my $pattern = "ABC()DEF"; my $string = "ABC()DEF"; if ($string =~ /\Q$pattern\E/) { print "match 1\n" } if ($string =~ /$pattern/) { print "match 2\n" }
    You can see that putting your variable between \Q and \E in the regex disables the ( and ) metacharacters in the pattern. (I think!).