Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Substitution backreference woes

by LanX (Saint)
on Jan 24, 2015 at 13:17 UTC ( [id://1114362]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Substitution backreference woes
in thread Substitution backreference woes

yeah sorry I wasn't able to test from Android, the problem is that the substitution part of s/// is supposed to be a literal. Otherwise you have to apply the /e eval modifiers.

my $string = 'Hello sailor'; my $regex = 'Hello (.*)'; # my $substitution = 'Goodbye \1'; $string =~ s/$regex/Goodbye $1/; print "string is now <$string> \n";

/usr/bin/perl -w /tmp/regex.pl string is now <Goodbye sailor>

Please note that \1 is somehow deprecated in the substitution part and will cause warnings.

Its only legitimate use is in the match part for backreference.

Cheers Rolf

PS: Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114362]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-29 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found