Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Using a regex capture as part of a varible

by soonix (Canon)
on May 07, 2020 at 15:08 UTC ( #11116548=note: print w/replies, xml ) Need Help??

in reply to Using a regex capture as part of a varible

Problem is, here, $1 is interpolated at the call to sed. That means: even before it is known if a match will occur and what will be matched. You could patch your copy of Rex::Commands::File to include /e flags for the two s/// operations in sed, but that is most certainly going to break other things.

In your case, it looks like you don't want to replace, anyway, but to insert. You could try whether turning your search pattern into a lookbehind might work.

Replies are listed 'Best First'.
Re^2: Using a regex capture as part of a varible
by nysus (Parson) on May 07, 2020 at 15:20 UTC

    Yes, good insight. It seems I'm using the wrong tool for the job. I've toyed with lookbehinds and never found a good use case that didn't hurt my brain but this seems like the perfect one.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116548]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-06-29 07:24 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (96 votes). Check out past polls.