CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [miller] Issues :matching variable $1,$2,... in replacement string: Edit Log



miller
User

Apr 21, 2011, 10:57 PM


Views: 9852
Re: [miller] Issues :matching variable $1,$2,... in replacement string


In Reply To

Code
use strict; 
use warnings;

my $v = q{There are 3 boys};
my $regx = q{\b(\d+)\b};
my $str = q{$1 of 10};

$v =~ s/$regx/qq{"$str"}/eeg;

print "$v";



Doing a double e modifier, basically just evals the right hand side twice. My original suggestion above becomes the following after the first eval


Code
$v =~ s/$regx/"$1 of 10"/eg;


Hence why I used multiple versions of the double quoted string.

I could also have done this for a bit more fun:


Code
$v =~ s/$regx/qq{qq{$str}}/eeg;



(This post was edited by miller on Apr 21, 2011, 10:58 PM)


Edit Log:
Post edited by miller (User) on Apr 21, 2011, 10:58 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives