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 (Patriarch) 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!