activeperl@listserv.activestate.com
[Top] [All Lists]

Re: Regexp substitution

Subject: Re: Regexp substitution
From: "John W. Kennedy"
Date: Sat, 15 Jul 2006 15:17:14 -0400
pDale wrote:
> On 7/15/06, John W. Kennedy <jwkenne@xxxxxxxxxxxxx> wrote:
>> But you can do it without using eval:
>>
>> use strict;
>> use warnings;
>> my $p1 = '^([^0-9]*)([0-9].*)$';
>> my $p2 = '"'.'$2 $1'.'"'; #Note wrapping it with double quotes
>> my $str = 'abc123xyz';
>> $str =~ s/$p1/$p2/ee; #Note double e
>> print $str, "\n";
> 
> Yes, that works too!  I like not using eval (it makes me feel "dirty" :) ).
> 
> Did you "quote-out" the double-quotes just to make them more obvious?  Because
>           $p2 = '"Incl. $1"';
> works just as well.

Partly to make it stand out, and partly because your original message 
said something about gathering the data from a file, where you wouldn't 
have included the quotes in the first place.

-- 
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
   -- Charles Williams.  "Taliessin through Logres: Prelude"

_______________________________________________
ActivePerl mailing list
ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

<Prev in Thread] Current Thread [Next in Thread>