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 8709727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:26:14+00:00 2026-06-13T04:26:14+00:00

Four very identical regular expressions. I am replacing the strings with the following scalar

  • 0

Four very identical regular expressions. I am replacing the strings with the following scalar values. How can this be more efficient?

$line =~ s/\[(receiver)\]/$receiver/g;
$line =~ s/\[(place)\]/$place/g;
$line =~ s/\[(position)\]/$position/g;
$line =~ s/\[(company)\]/$company/g;

Thank you.

  • 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-13T04:26:15+00:00Added an answer on June 13, 2026 at 4:26 am

    Consider just using a real templating system. Template Toolkit for instance is very easy.

    Leaving that aside, you say you want it more efficient. Is its current perceived inefficiency a problem? If not, leave it alone.

    You could do it all in one pass:

    my %subst = (
        'receiver' => $receiver,
        'place'    => $place, 
        'position' => $position,
        'company'  => $company,
    );
    $line =~ s/\[(receiver|place|position|company)\]/$subst{$1}/g;
    

    but this will act differently if, for instance, $receiver is ‘place’.

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

Sidebar

Related Questions

I am very new and extremely confused as to how I can accomplish this
I have very simple piece of code. The goal is when i input four-digit
A have a struct with four very large matrices that correspond to grayscale images.
Very very basic question but I've got the following HTML: <input type=text id=nspcc value=0
This is a very newbie question I fear... I was wondering if there are
I'm new here, and this is my very first post. I have a very
My C# program has a very strange behavior. I'm using four ''hacky'' pinvoke methods
I'm VERY new to regex and can't get my head wrapped around it completely
This is probably a very basic error on my part. Here's what I did:
I'm trying to setup a very basic jQuery image gallery. You can see my

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.