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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:23:44+00:00 2026-05-25T17:23:44+00:00

I want to store text/string in a text field in a database. This string

  • 0

I want to store text/string in a text field in a database.
This string has the variable $name in it.
When I pull it out of the database, I want that variable to be substituted with the value I define before I print the string.

   # Variable I want to substitute #
1. $name='John';

   # needs to be read from database #
2. $txt{'hello'}="Hello ${name}, How are you?";

3. print "<tag>$txt{'hello'}</tag>";

It prints Hello John, How are you? as required, but when 2nd line is read from database, it displays Hello ${name}, How are you?.

Some things I found are:

  1. Locale::Maketext
  2. $string =~ s/(\$\w+)/$1/eeg;
  3. my $string = sprintf 'Say hello to %s and %s', $foo, $bar;

Can someone guide me about how to go about it?

  • 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-25T17:23:44+00:00Added an answer on May 25, 2026 at 5:23 pm

    What you’re describing is a template. There are lots of template systems on CPAN of varying degrees of complexity. Text::Template and Template Toolkit are a couple of popular ones. You don’t want to let your templates access arbitrary variables; that’s a security hole. Instead, put the variables they’re allowed to access into a hash.

    If all you need is a very simple system, you can do something like this:

    sub fill_in_template
    {
      my ($text, $values) = @_;
      $text =~ s/ \$\{ ( [^}\s]+ ) \} /$values->{$1}/gx;
      return $text;
    }
    
    my %txt;
    my %values = (name => 'Your Name');
    
    my $template  = 'Hello ${name}, How are you?'; # $name NOT interpolated
    $txt{'hello'} = fill_in_template($template, \%values);
    
    print "<tag>$txt{'hello'}</tag>\n";
    

    You might add some error checking in case the template uses a field that’s not defined. But if you need something more complicated than that, you’re probably better off picking an existing template system from CPAN.

    Locale::Maketext is intended for internationalization (so your app can produce output in multiple languages without your translators needing to work on the code directly) and is not the sort of template engine you’re looking for.

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

Sidebar

Related Questions

I am trying to query a string (TEXT field in the database) and want
public Drawable icon; \\ Some value in this field I am creating a database
I want to take a string and store it in a MYSQL db. This
I want to read each line from a text file and store them in
There is some html text stored in the Database which I want to show
I want to execute some mysql statements that are stored in a text file
I want to store the current URL in a session variable to reference the
I want to store a large number of sound files in a database, but
I want to store a a c# DateTimeOffset value in a SQL Server 2005
I want to store a large result set from database in memory. Every record

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.