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

RE: using search backreferences in a variable

Thread Previous | Thread Next
From:
Nikola Janceski
Date:
March 28, 2002 08:01
Subject:
RE: using search backreferences in a variable
Message ID:
1449413DA482D311B67000508B5A12F50592DF8F@nyexchange01.summithq.com
\1 is obsolete.
try $1 and you  also have use the /ee
and fix your $replace for the /ee
read perldoc perlre

$match = qr/cat(\d+)/;
$replace = '$1. "dog"';
$_ = "cat15";
s/$match/$replace/gee;
print $_, "\n";  # prints -->  15dog

> -----Original Message-----
> From: Bryan R Harris [mailto:Bryan_R_Harris@raytheon.com]
> Sent: Thursday, March 28, 2002 10:46 AM
> To: Beginners Perl Mailing List
> Subject: using search backreferences in a variable
> 
> 
> 
> Why does this segment not work properly?
> 
> $match = "cat(\d+)";
> $replace = "\1dog";
> $_ = "cat15";
> s/$match/$replace/g;
> print $_;  # prints -->  \1dog
> 
> Any ideas?
> 
> TIA.
> 
> - B
> 
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> 

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


Thread Previous | Thread Next


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