Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Evaluating variables within a string

by Dallaylaen (Chaplain)
on Dec 06, 2017 at 05:14 UTC ( [id://1205000]=note: print w/replies, xml ) Need Help??


in reply to Evaluating variables within a string

As it stands, a simple sprintf would work just fine:
my $string = "first_string ref[%u] second_string %s.ref[%u] third_stri +ng"; for (my $i=0; $i<5; $i++) { my $new_string = sprintf $string, $i, "parent_ref", $i; print "$i: $new_string\n"; }
Maybe the real case requires more sophisticated template engine, something like String::Formatter, but from the snippet it doesn't look like that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205000]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-28 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found