develooper Front page | perl.beginners | Postings from March 2002

RE: using search backreferences in a variable

Thread Previous
From:
David Gray
Date:
March 28, 2002 08:03
Subject:
RE: using search backreferences in a variable
Message ID:
001301c1d672$171d8170$7800a8c0@3b2.com
> Why does this segment not work properly?
> 
> $match = "cat(\d+)";
> $replace = "\1dog";
> $_ = "cat15";
> s/$match/$replace/g;
> print $_;  # prints -->  \1dog
> 
> Any ideas?

Try replacing the "\1dog" with '${1}dog' in the line where you define
$replace. That should solve your problem.

 -dave



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About