Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Filling a string with Text::Template

by Anonymous Monk
on Jun 12, 2019 at 09:22 UTC ( #11101273=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I'm not able to fill a string as in the example below with Text::Template. Where is the mistake?
Thanks
use strict; use Text::Template; my $user_info = 'u1'; my $site = 'a'; my $string = './{$user_info}.{$site}.txt'; my $template = Text::Template->new(TYPE =>'STRING',SOURCE=>$string); $string = $template->fill_in({site=>$site,user_info=>$user_info}); print "$string\n";

Replies are listed 'Best First'.
Re: Filling a string with Text::Template
by Corion (Pope) on Jun 12, 2019 at 09:25 UTC

    The documentation doesn't show your usage of ->fill_in but a different usage:

    my $result = $template->fill_in(HASH => \%vars);

    Maybe using the documented version helps?

    my $result = $template->fill_in(HASH => { ... });

    Also, you're overwriting the template in $string with the value. This shouldn't be problematic but it's confusing.

      Thanks a lot!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11101273]
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2019-06-25 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (107 votes). Check out past polls.

    Notices?