in reply to String substitution

I'm not clear about what you want.
How is this?:

#!/usr/bin/perl use strict; use warnings; my $str = 'hello nr34 , 56, hi'; print "input string=$str\n"; $str =~ s/.*nr(\d+)([^\d]+)(\d+)(.*)/"calc(nr$1)$2".eval{$3*4}."$4";/e +; print "output string=$str\n"; __END__ Prints: input string=hello nr34 , 56, hi output string=calc(nr34) , 224, hi
Please give some more example lines.
I doubt that the above solves the "problem".

Replies are listed 'Best First'.
Re^2: String substitution
by AnomalousMonk (Archbishop) on Sep 20, 2016 at 02:56 UTC
    $str =~ s/.*nr(\d+)([^\d]+)(\d+)(.*)/"calc(nr$1)$2".eval{$3*4}."$4";/e;

    FWIW: The separate  eval{$3*4} is not needed (although it does no harm) because the entire replacement expression is already being eval-ed:
        $str =~ s/.*nr(\d+)([^\d]+)(\d+)(.*)/"calc(nr$1);$2" . $3*4 . $4/e;
    (tested, and I also stuck the semicolon back where kepler seems to want it).


    Give a man a fish:  <%-{-{-{-<