On Fri, 1 Jun 2001, Danilo-Fanton Da Silva wrote:
> In the .pl program I have a hash table of hash tables like:
>
> my %hash = {
> id => {
> class => '1030',
> instance => '1.0.0987',
> },
> attrs => {
> label => 'network',
> value => '20010',
>
> },
> };
I think you're confusing a hash and a hash reference. You may want:
my $hash_ref = { name => "value",
name2 => "value2",
};
This will create a reference to a hash in $hash_ref. This is a shorthand
way of doing:
# create my hash (note the '(' and ')' not '{' and '}')
my %hash = ( name => "value",
name2 => "value2",
name3 => { foo => "bob",
bar => "baz",
},
);
# take a ref to it
my $hash_ref = \%hash;
Note that name3 in the above examples is a short way of storing a
reference to the hash containing the foo and bar entries in name3.
> I'd like to use this hash in the template file. I tried:
>
> my $vars = {
> hash_table => %hash,
> };
>
Now that you're using a reference to a hash you can do
my $vars = {
hash_table => $hash_ref,
}
And Template Toolkit will do the right thing so you can say
[% # print out 'value' %]
[% hash_table.name %]
[% # print out 'bar' %]
[% hash_table.name3.foo %]
and Template Toolkit will automatically de-reference your hashes and print
out the correct thing.
I recommend re-reading the perlref manpage which is rather good and goes
into the perl side of this very nicely.
Hope that's been some help.
Mark.
--
s'' Mark Fowler Technology Developer Profero Ltd
http://www.profero.com/ [EMAIL PROTECTED] 020 7700 9960
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}