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 83831

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:50:08+00:00 2026-05-10T21:50:08+00:00

I have been programming in Perl, off and on, for years now, although only

  • 0

I have been programming in Perl, off and on, for years now, although only sporadically is it my primary language. Because I often go months without writing any perl, I rely heavily on my dog-eared Camel Book to remind me how to do things. However, when I copy recipes verbatim with no understanding, this bothers me. This is one of the most vexing: On page 154 of the 3rd edition Camel, there is an example for ‘modifying strings en passant, which reads like this:

($lotr = $hobbit) =~ s/Bilbo/Frodo/g; 

Q1) what is going on here? On what, exactly, is the regex operating?

Q2) Is this near-magical syntax necessary for such a basic operation as ‘take a string from $a, modify it with a regex, place result in $b’?

Q3) How do I do this operation using the loop default variable as the initial string?

Apologies in advance to Perl dreamers for whom the above looks perfectly natural.

  • 0 0 Answers
  • 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. 2026-05-10T21:50:09+00:00Added an answer on May 10, 2026 at 9:50 pm

    Hmmm… ($lotr=$hobbit) =~ s/Bilbo/Frodo/g is one of the many magicks of Perl. Now for some answers.

    Q1) $lotr is being assigned the value contained in $hobbit. After the assignment, we can forget about the source variable. Treat ($lotr = $hobbit) as it’s own statement as-if we had written:

    $lotr = $hobbit; $lotr =~ s/Bilbo/Frodo/g; 

    instead. The regex is operating on $lotr.

    Q2) The syntax is simply a one-line version of the snippet given above. Think of it as ‘copy the string from $a, copy it into $b, and modify $b with the regex’ instead of ‘take a string from $a, modify it with a regex, place result in $b‘

    Q3) I’m assuming that you mean the default pattern searching space by ‘loop default variable’? In that case, just use $_ instead of $hobbit:

    while (<>) {   chomp;   ($lotr = $_) =~ s/Bilbo/Frodo/g;   print '\$lotr = [$lotr]\n';   print '\$_    = [$_]\n'; } 

    Interestingly enough, the magic var $_ is not modified by this operation. This is how you can conclude that the assignment happens before the regex substitution and that the substitution does not interact on the default pattern space in any way.

    And for the experienced Perl programmers thing… I don’t know too many people that are thrown by some piece of Perl syntax regardless of how long they have been staring at it ‘cept Mr. Schwartz of course 😉

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

Sidebar

Ask A Question

Stats

  • Questions 181k
  • Answers 181k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As @Ngu has said, put it on the top of… May 12, 2026 at 4:11 pm
  • Editorial Team
    Editorial Team added an answer The way you declare the ItemsPanelTemplate is incorrect : you're… May 12, 2026 at 4:11 pm
  • Editorial Team
    Editorial Team added an answer I have done something similar for my online chess site… May 12, 2026 at 4:11 pm

Related Questions

I've been programming in C-derived languages for a couple of decades now. Somewhere along
I've been programming in Perl for a while, but I never have understood a
I have been programming since 1999 for work and fun. I want to learn
In the past I've worked with -Wall and other switches for gcc to eliminate

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.