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

Regexp substitution

Subject: Regexp substitution
From: pDale
Date: Sat, 15 Jul 2006 00:33:23 -0400
I'm having a hard time "asking the question" to Google...

I want to read regular expressions from a config file to use in
substitions, but I can't get the regexp to work for memorized
groupings.  A barebones example of the operations I want to do:

__CODE_STARTS__
my $p1 = "^([^0-9]*)([0-9].*)\$";   # these would actually be read from a file
my $p2 = "\$2 \$1";

my $str = "abc123xyz";

$str =~ s/$p1/$2 $1/;

print "$str\n";
# This prints out "123xyz abc", which is what I want

$str = "abc123xyz";

$str =~ s/$p1/$p2/;

print "$str\n";
# This prints out "$2 $1", $1 and $2 weren't interpreted :(
__CODE_ENDS__

So, what really simple thing am I doing wrong?

TIA

-- 
pDale Campbell
Desperation = A Rope Ends It
_______________________________________________
ActivePerl mailing list
ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

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