Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:45:30+00:00 2026-06-15T00:45:30+00:00

$test=’abc=def’; $replacement=’$1=ghj’; $test =~ s/(.+)=(.+)/$replacement/; print $test; It prints: $1=ghj How can I treat

  • 0
$test='abc="def"';
$replacement='$1="ghj"';
$test =~ s/(.+)="(.+)"/"$replacement/;
print $test;

It prints:

$1=ghj

How can I treat $replacement to be interpreted?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:45:31+00:00Added an answer on June 15, 2026 at 12:45 am

    There are approximately 3 answers to this question.

    • Your replacement “string” is actually code to be evaluated at match time to generate the replacement string. That is, it is better represented as a function:

    my $test = 'abc="def"';
    my $replacement = sub { $1 . '="ghj"' };
    $test =~ s/(.+)="(.+)"/$replacement->()/e;
    print $test;
    
    • If you don’t need the full power of arbitrary Perl expressions (or if your replacement string comes from an external source), you can also treat it as a template to be filled in with the match results. There is a module that encapsulates this in the form of a JavaScript-like replace function, Data::Munge:

    use Data::Munge qw(replace);
    my $test = 'abc="def"';
    my $replacement = '$1="ghj"';
    $test = replace $test, qr/(.+)="(.+)"/, $replacement;
    print $test;
    
    • Finally, you can represent Perl code as a string to be eval‘d. This is not only inefficient but also fraught with quoting issues (you have to make sure everything in $replacement is syntactically valid Perl) and security holes (if $replacement is generated at runtime, especially if it comes from an external source). My least favorite approach:

    my $test = 'abc="def"';
    my $replacement = '$1 . "=\\"ghj\\""';
    $test =~ s/(.+)="(.+)"/eval $replacement/e;
    print $test;
    

    (The s//eval $foo/e part can also be written as s//$foo/ee. I don’t like to do that because eval is evil and shouldn’t be more hidden than it already is.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

test.py def add(a,b): print a,b,a+b return a+b c program #include <python.h> int _tmain(int argc,
test code is: console.log(true && abc);//abc who can tell me why the result is
Test.text abc,def,ghi,jkl,... Is there anyway possible to insert each one to each row in
#test code: #!/bin/bash #~/test/test.sh trap echo 'testmessage' DEBUG while : do echo abc sleep
Test Site Example: http://cincinnati-website-design.net/sandbox/ I am using the Avada Theme and can't seem to
test.sh parameter in test.sh , how can I get the parameter ?
Test string: the%20matrix%20 How can I delete the last three chars? Using this code
test.php?t=xxx,y=sss This is how the user inputs data to my script. How can I
Test Function def GetTestFile(): sshConn = paramiko.SSHClient() sshConn.load_system_host_keys() sshConn.connect(host, port, usrnm, pwrd) (connin, out,
Test script use JSON; $\ = \n; my $big_number = '12345678901234567890123456'; print $big_number; print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.