in reply to Re: Printing to stdout an array of strings and scalar references
in thread Printing to stdout an array of strings and scalar references

Hi Eily

To clarify the Template Toolkit is a web centric tool?
I am not actually interfacing this perl code with any kind of web front end, it is purely a CLI operation, however I had considered using a similar method with a multidimensional hash instead of an array, but when I thought about the complexities of keeping the ordering correct compared to my current requirements for this script an array just seemed simpler.
Anyhow, you have reminded me that I should take another look at Text::Template perhaps I could achieve some similar results using that.

Thanks for your assistance.

  • Comment on Re^2: Printing to stdout an array of strings and scalar references

Replies are listed 'Best First'.
Re^3: Printing to stdout an array of strings and scalar references
by hippo (Archbishop) on Oct 25, 2017 at 08:35 UTC
    To clarify the Template Toolkit is a web centric tool?

    Actually, no. It is a perfectly generic templating system - flexible and extensible. The breadth of the facilities which it offers has been recognised as a benefit by many web application developers and so they have used it for that purpose but it is not web-centric.

    Here is your script re-written using TT2, for example:

    #!/usr/bin/env perl use strict; use warnings; use Template; my $t = { count => 42, completed => 6 }; my $outtt2 = "\rProcessing: [% count %] files to process ; [% completed %] file c +ompleted\n"; my $template = Template->new; notify_progress (); $t->{completed} = 7; notify_progress (); sub notify_progress { $template->process (\$outtt2, $t); }

    I've kept the notify_progress() subroutine so you can see the difference. In a real script this subroutine would disappear and just be replaced by the call to process() inline. If you have a need for templating (and most of us do sooner or later) then do take a look at TT2. It is big and has a steep learning curve compared to others but there are tutorials to help you through and if you use it as I have you will be far less likely to hit a limitation of your templating system than with other, lighter alternatives.