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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:11:14+00:00 2026-06-12T10:11:14+00:00

I have found ways of doing this if the variables in the string are

  • 0

I have found ways of doing this if the variables in the string are simple scalars such as “$foo = 5” using regex. But the issue is what if the variable in the string is:
$foo->{bar} which is equal to 5.

So sample string is:

“This is a string with hash value of $foo->{bar}”.

How can I expand that out to read:

“This is a string with hash value of 5”

Thanks.

Edit for more explanation:

I have a string literal (I believe? I am not the best at the vocab of this) that is “Lorem Ipsum $foo->{bar} Lorem Ipsum” that I received from some text source. I want to take that string, replace all the variable names with the actual value of the variable in my code.

  • 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-12T10:11:15+00:00Added an answer on June 12, 2026 at 10:11 am

    What you have there is called a “template”. As such, you are looking for a templating system.

    Assuming those quotes aren’t actually in the string, the only template system I know capable of understanding that templating language is String::Interpolate.

    $ perl -E'
       use String::Interpolate qw( interpolate );
       my $template = q!This is a string with hash value of $foo->{bar}!;
       local our $foo = { bar => 123 };
       say interpolate($template);
    '
    This is a string with hash value of 123
    

    If the quotes are part of the string, what you have there is Perl code. As such, you could get what you want by executing the string. This can be done using eval EXPR.

    $ perl -E'
       my $template = q!"This is a string with hash value of $foo->{bar}"!;
       my $foo = { bar => 123 };
       my $result = eval($template);
       die $@ if $@;
       say $result;
    '
    This is a string with hash value of 123
    

    I strongly recommend against this. I’m not particularly found of String::Interpolate either. Template::Toolkit is probably the popular choice for templating system.

    $ perl -e'
       use Template qw( );
       my $template = q!This is a string with hash value of [% foo.bar %]!."\n";
       my %vars = ( foo => { bar => 123 } );
       Template->new()->process(\$template, \%vars);
    '
    This is a string with hash value of 123
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay everyone, I have found multiple ways of doing this and I have even
i have found some ways but they are actually reading frames and applying transition
I have found already some similar discussion on this, but would like to investigate
This seems like a very simple question, but I've only found complicated answers. I've
This is my first time using StackOverflow myself. I have found many answers to
I've searched and searched stackoverflow and www, but have found no answers to this
I have found two ways to extract matches in Python: 1. def extract_matches(regexp, text):
I have found that I have no problem using require to load something like
I have found many great answers to this from a year ago (when it
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that

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.