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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:17:30+00:00 2026-05-24T09:17:30+00:00

Assuming that I must do this substitution using a single substitution, what is the

  • 0

Assuming that I must do this substitution using a single substitution, what is the preferred method to avoid this error:

Use of uninitialized value $2 in concatenation (.) or string at -e line 1.

With this Perl code:

perl -e 'use strict;use warnings;my $str="a";$str=~s/(a)|(b)/$1foo$2/gsmo;'

The goal here is to either print “afoo” or “foob” depending on what $str contains.

I can use no warnings; but then I am worried I will miss other “real” warnings. I also know that using one pattern makes this convoluted but my actual pattern is much more complicated.

If you care the actual replacements are closer to:

#!perl
my $search = q~(document\.domain.*?</script>)|(</head>)~;
my $search_re = qr/$search/smo;
my $replace = q("$1
<script src=\"/library.js\"></script>
$2");
while (<*.tmpl>) {
  my $str = fead_file($_);
  $str =~ s/$search_re/$replace/gee;
}

But even more complicated, basically the above code just reads from a DB to get the search & replace and then does them to the template. Having to run this script twice with every commit would introduce too much overhead, apparently… so says them…

  • 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-05-24T09:17:31+00:00Added an answer on May 24, 2026 at 9:17 am

    You could:

    my $replace = q("@{[$1||'']}
    <script src=\"/library.js\"></script>
    @{[$2||'']}");
    

    (using // instead of || on 5.10+)

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

Sidebar

Related Questions

Assuming that I want to use a hash as an ID instead of a
Assuming that I cannot run something like this with Fabric: run(svn update --password 'password'
Assuming that I must deploy an asp.net app over the following 3 servers: 1)
I wrote a method(getDirTree1) that makes listing all directories from the root, using the
Assuming that writing nhibernate mapping files is not a big issue....or polluting your domain
assuming that I know the PID of a process and want to do a
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Assuming that best practices have been followed when designing a new database, how does
Assuming that I have a typedef declared in my .h file as such: typedef
Assuming that I know there is a git-daemon running at git://git.mycompany.com , how can

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.