SavannahLion has asked for the wisdom of the Perl Monks concerning the following question:
The <TMPL_LOOP> tag is a bit more complicated than <TMPL_VAR>. The <TMPL_LOOP> tag allows you to delimit a section of text and give it a name. Inside this named loop you place <TMPL_VAR>s. Now you pass to param() a list (an array ref) of parameter assignments (hash refs) for this loop. The loop iterates over the list and produces output from the text block for each pass. Unset parameters are skipped. Here's an example: In the template: <TMPL_LOOP NAME=EMPLOYEE_INFO> Name: <TMPL_VAR NAME=NAME> <br> Job: <TMPL_VAR NAME=JOB> <p> </TMPL_LOOP> In the script: $template->param(EMPLOYEE_INFO => [ { name => 'Sam', job => 'progra +mmer' }, { name => 'Steve', job => 'soda + jerk' }, ] ); print $template->output(); The output in a browser: Name: Sam Job: programmer Name: Steve Job: soda jerk As you can see above the <TMPL_LOOP> takes a list of variable assignments and then iterates over the loop body producing output.
Apparently, I'm not having much luck in understanding this. I think it's either because the only time I have to play with Perl for the last several weeks is between 10:00 PM and 1:00 AM, or the total program is just so large and complex, so my poor brain just can't wrap itself around this.
Whenever I experiment with this, I always get a "Pseudo-hashes deprecated" message. I even found a very similar example, but running that example yields an identical error message. Unfortunately, I think there was more to that example, but I lost my place in the PM search and haven't found it yet.
It looked something like:
my $ph = [ { alpha => 1, beta => 2, gamma => 3, delta => 4, epsilon => + 5 }, #hashref "val a", "val b", "val c", "val d", "val e" ]; + # maps to these values # Print some of the elements print $ph->[1], "\n"; print $ph->{ alpha }, "\n"; print $ph->{ epsilon }, "\n";
How is it that when I try to copy this method, I get that such a blatant warning, but Template.pm gets away with using it?
----
Thanks for your patience.
Prove your knowledge @ HLPD
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pseudo-hashes deprecated
by ikegami (Patriarch) on Oct 17, 2004 at 09:23 UTC | |
|
Re: Pseudo-hashes deprecated
by jdalbec (Deacon) on Oct 17, 2004 at 19:00 UTC | |
|
Re: Pseudo-hashes deprecated
by BUU (Prior) on Oct 17, 2004 at 09:12 UTC |