[tpm] how to resubstitute a captured value

Fulko Hew fulko.hew at gmail.com
Fri Apr 19 08:40:19 PDT 2013

On Fri, Apr 19, 2013 at 11:27 AM, Dave Doyle <dave.s.doyle at gmail.com> wrote:
> So long as start and end don't have to be regexes themselves:

... snip ...

Its not that start and end are regexes, its that the match and replace
need to be regexes

The two pattens must be wholly contained within variables
(because they are coming from a config file/table)
so that means the right hand side needs to be interpolated?

Therefore the constraint is:

use strict;
while (my $line = <DATA>) {
    my $match = '^-?(.+?):?$';
    my $replace = '-$1:';

    $line =~ s/$match/$replace/;   <= something magic happens here
given $match and $replace
    print $line;

More information about the toronto-pm mailing list