Mad_Mac has asked for the wisdom of the Perl Monks concerning the following question:
I have a regex to replace dashes between words with spaces, like this
$newName =~ s/(\w)-(\w)/\1 \2/g;It works fine, but I get a warning saying
\1 better written as $1 at newstuff_rename.pl line 46. \2 better written as $2 at newstuff_rename.pl line 42.
This seems to contradict the documentation, which says:
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 unsatisfactory results.
Am I misunderstanding this?
Got it. Thanks for the clarification!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex backreferences
by ikegami (Patriarch) on Mar 20, 2011 at 07:06 UTC | |
|
Re: Regex backreferences
by jwkrahn (Abbot) on Mar 20, 2011 at 07:07 UTC |