APM: Regular expression with double variable substitution

Fluhmann, Jeremy jeremy at stuact.tamu.edu
Fri Jan 6 13:07:16 PST 2006


This works, but I'm not sure it's what you're trying to do.

$t = '34:56';
$t =~ s/(\d+):(\d+)/"$1 - $2"/e;

Jeremy Fluhmann
Microcomputer Specialist
Department of Student Activities
Texas A&M University
979-458-4649
jeremy at stuact.tamu.edu

-----Original Message-----
From: austin-bounces at pm.org [mailto:austin-bounces at pm.org] On Behalf Of
Evan Harris
Sent: Friday, January 06, 2006 2:05 PM
To: Austin Perlmongers
Subject: APM: Regular expression with double variable substitution


Is there any way to make perl re-interpret the contents of a variable
that
is used as a substitution part of a regex?  I thought that the /e
modifier
would do this, but it doesn't seem to work.

For example:

$s = '$1 - $2';
$t = '34:56';
$t =~ s/(\d+):(\d+)/$s/e;

After this, $t is equal to '$1 - $2', rather than the desired '34 - 56'.

I think it may be possible by using an eval, but I don't want the power
(and
the danger) of allowing any perl code, I just want to fill in nested
variables.

Evan


_______________________________________________
Austin mailing list
Austin at pm.org
http://mail.pm.org/mailman/listinfo/austin




More information about the Austin mailing list