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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:21:47+00:00 2026-05-11T09:21:47+00:00

If I had: $foo= 12.bar bar bar|three; how would I insert in the text

  • 0

If I had:

$foo= '12.'bar bar bar'|three'; 

how would I insert in the text ‘..’ after the text 12. in the variable?

  • 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. 2026-05-11T09:21:48+00:00Added an answer on May 11, 2026 at 9:21 am

    Perl allows you to choose your own quote delimiters. If you find you need to use a double quote inside of an interpolating string (i.e. '') or single quote inside of a non-interpolating string (i.e. '') you can use a quote operator to specify a different character to act as the delimiter for the string. Delimiters come in two forms: bracketed and unbracketed. Bracketed delimiters have different beginning and ending characters: [], {}, (), [], and <>. All other characters* are available as unbracketed delimiters.

    So your example could be written as

    $foo = qq(12.'bar bar bar'|three); 

    Inserting text after ’12.’ can be done many ways (TIMTOWDI). A common solution is to use a substitution to match the text you want to replace.

    $foo =~ s/^(12[.])/$1../; 

    the ^ means match at the start of the sting, the () means capture this text to the variable $1, the 12 just matches the string '12', and the [] mean match any one of the characters inside the brackets. The brackets are being used because . has special meaning in regexes in general, but not inside a character class (the []). Another option to the character class is to escape the special meaning of . with \, but many people find that to be uglier than the character class.

    $foo =~ s/^(12\.)/$1../; 

    Another way to insert text into a string is to assign the value to a call to substr. This highlights one of Perl’s fairly unique features: many of its functions can act as lvalues. That is they can be treated like variables.

    substr($foo, 3, 0) = '..'; 

    If you did not already know where '12.' exists in the string you could use index to find where it starts, length to find out how long ’12.’ is, and then use that information with substr.

    Here is a fully functional Perl script that contains the code above.

    #!/usr/bin/perl  use strict; use warnings;  my $foo = my $bar = qq(12.'bar bar bar'|three);   $foo =~ s/(12[.])/$1../;  my $i = index($bar, '12.') + length '12.'; substr($bar, $i, 0) = '..';  print 'foo is $foo\nbar is $bar\n'; 

    * all characters except whitespace characters (space, tab, carriage return, line feed, vertical tab, and formfeed) that is

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

Sidebar

Related Questions

I have a data.frame with entries like: variable importance order 1 foo 0.06977263 1
Please forgive the bad title - I had a hard time trying to think
My brain had a segfault this morning trying to understand exactly how and when
Part 1: I have a call to layout(:default){|path,wish| wish !~ /rss|atom|json/} but requests to
I am working on the frontend of a project that gives me Java Expression
I think I have done this before, but it could also be a function
I want to write a function that calls both plot() and legend() and it
I am doing OO javascript for the first time. I have read about inheritance
I want to run a query on an Oracle database and for each column
To be honest, I'm feeling pretty stupid right now. But this simply isn't working

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.