Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Using a regex capture as part of a variable

by hippo (Bishop)
on May 07, 2020 at 15:05 UTC ( [id://11116547]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using a regex capture as part of a varible
in thread Using a regex capture as part of a varible

You need to set up your replacement string correctly. Once that's done it runs fine with the /ee modifier:

use strict; use warnings; use Test::More tests => 1; my $new = 'blah'; my $string = 'asdfjkjl'; my $find = '(asd)'; my $replace = qq#\${1} . '$new'#; my $result = replace ($string, $find, $replace); is $result, 'asdblahfjkjl'; sub replace { my $string = shift; my $left = shift; my $replace = shift; $string =~ s/$left/$replace/ee; return $string; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found