Hello All,

I'm using '-w' like any good hacker, but every time I try to use backreferences in my regexps, I get a warning "\1 better written as $1 at...."

I'm confused because, according to perlretut:
"Although $1 and \1 represent the same thing, care should be taken to use matched variables $1, $2, ... only outside a regexp and backreferences \1, \2, ... only inside a regexp; not doing so may lead to surprising and/or undefined results."

The other source of relevant information seems to be here:
<http://www.perl.com/doc/manual/html/pod/perlre.html#WARNING_on_1_vs_1>
However, I'm having trouble understanding if it is referring to using backreferences in general, or to a particular case where using \1 instead of $1 is a bad idea.


Here is an example of one of my regexps that produces this warning:
$text =~ s!(.*?)(\()(.*?)(\))!<a\ href=\"\3\" alt=\"\3\">\1<\/a>!g;

Should I be using $1 and $3 instead of \1 and \3 in this case, and if so, why?

Thanks in advance,
Adam

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to