Keep It Simple, Stupid | |
PerlMonks |
Re: Text::Templateby PotPieMan (Hermit) |
on Oct 23, 2001 at 03:49 UTC ( [id://120659]=note: print w/replies, xml ) | Need Help?? |
A couple of warnings on the use of Text::Template. If you use strict like a good Perl programmer, Text::Template will not see your variables as you might expect. Since templates are opened in new scopes by Text::Template, this behavior makes perfect sense, but is rather annoying.
You have two options available when you run into this problem:
Also, I found that Text::Template doesn't behave exactly as you might expect in dereferencing variables. For instance, take the following code as an example: Assuming your template delimiters are the default ({ and }), you might expect to use {$measurements->{'temperature'}->{'current'}} to print the current temperature in your template. I had to use {$measurements{'temperature'}{'current'}} instead, and I'm not entirely sure why. (If any monks have an idea, please let me know.) This was with version 1.41 (current as of 2001-10-22); I have emailed the author with the question and am awaiting a response. With all that said, Text::Template is a great module for removing more of the display element from your code. For my scripts, I probably would have gone with either HTML::Template or Template Toolkit if they had been readily available. Update: I overlooked one important section of the documentation. As Dominus politely pointed out in an email, the HASH section explains how the templates are filled. Indeed, If the value is a reference to an array, then @key is set to that array. If the value is a reference to a hash, then %key is set to that hash. Similarly if value is any other kind of reference.I always manage to miss the important parts of documentation. :-) --PotPieMan
In Section
Module Reviews
|
|