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

  • Home
  • SEARCH
  • 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 811107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:59:28+00:00 2026-05-15T00:59:28+00:00

I have two Perl one liners: perl -pe s/\b$a\b/$b/g if m/param1 / test and

  • 0

I have two Perl one liners:

perl  -pe "s/\b$a\b/$b/g if m/param1 /"  test

and

perl  -pe "s/\b$a\b/$b/g unless /^#/" test

How can I combine theif m/somthing/ and the unless /something/, like:

[root@localhost tmp]#  perl  -pe "s/\b$a\b/$b/g if m/param1/ unless /^#/"  test
syntax error at -e line 1, near "m/param1/ unless"
  • 1 1 Answer
  • 1 View
  • 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-15T00:59:28+00:00Added an answer on May 15, 2026 at 12:59 am

    On an unrelated note, you may want to add the \Q and \E escape sequences around $a in your regex:

    perl  -pe "s/\b\Q$a\E\b/$b/g if m/param1 /"  test
    

    They escape any characters that are special to regexes. If you intend for $a to hold a regex you should probably move the word boundary assertions (\b) into it.

    No matter what you choose to do, you will need to be careful with values in $a and $b. For instance:

    a="/"
    b="slash"
    perl  -pe "s/\b\Q$a\E\b/$b/g if m/param1 /"  test
    

    will cause a syntax error. One solution to this is to not use environment variables to replace code. Perl allows you access to the environment through the %ENV hash:

    perl -pe 's/\b\Q$ENV{a}\E\b/$ENV{b}/g if m/param1 /' test
    

    Notice the use of single ticks to avoid treating $ENV as a shell variable.

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

Sidebar

Related Questions

I have two perl scripts; one acts like the client (and queries); the other
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have two Perl files: action.pl and the other is test.pl action.pl has a
I have a perl script which i'd like to spawn a process. It can
I want to parse a large XML file and I have two options: Perl
I have two folders php and perl . They contain index.php and index.pl ,
I have the opportunity to take a two day class on Perl 6 with
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two tab-delimited genome sequence files (SAM format), and I would like to
Apparently, a Perl script I have results in two different output files depending on

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.