Re: [Templates] Lost in Templation

[prev] [thread] [next] [Date index for 2004/06/18]

From: Jeff Anderson
Subject: Re: [Templates] Lost in Templation
Date: 01:44 on 18 Jun 2004
It's really quite simple if you don't already get it.

%Size is a hash. It is not a reference. You might declare it like so

my %Size = ( foo => 'bar', baz => 'qux' );

$Size is not a hash. It might be a SCALAR, it might be a reference,
perhaps to a HASH. You might declare it like so:

my $Size = { foo => 'bar', baz => 'qux' };

or

my $Size = \%Size; # a direct reference to %Size

or

my $Size = {%Size} # a reference to a copy of %Size

Since process(0 expects a HASH reference, you can't just pass it %Size
directly, you have to pass a reference or a copy:

$sut->process($filename, \%Size, \$msgbody) or die $sut->error;

However, if $Size really is a HASH reference, then you just pass it 'as is'

$sut->process($filename, $Size, \$msgbody) or die $sut->error;

See http://perlmonks.com/index.pl?node_id=69927&displaytype=print for
a great reference on this stuff.

On Wed, 16 Jun 2004 18:15:23 -0700 (PDT), Roderick A. Anderson
<raanders@xxx.xxx> wrote:
> I'm am once again totally confused by the errors I'm getting when doing a
> _very_ simple process.
> 
> Here is the abbreviated code.
> 
>     my $sut =
>         Template->new({INCLUDE_PATH => ['/root/bin/templates/']});
>     my $filename = 'largemail.tt';
>     my $msgbody = '';
> 
>     $sut->process($filename, \$Size, \$msgbody)
>         || die $sut->error();
> 
> If I change the array reference '\$msgbody' to a simple scalar '$msgbody'
> I get the filled in template returned to the screen.
>    '\$Size' is a global and actually an array but using '\%Size' gives me
> errors also but more of them  :-(.
> 
> So here is the error I'm getting while running the whole script through
> the debugger.  Of all htepermutations I tried this gave me
> the shortest error message.  Where have I gone wrong?
> 
> Not a HASH reference at /usr/lib/perl5/site_perl/5.8.0/Template/Service.pm
> line 79.
> 
> Template::Service::process('Template::Service=HASH(0x8554848)','largemail.tt','SCALAR(0x893fb20)')
> called at /usr/lib/perl5/site_perl/5.8.0/Template.pm line 76
> 
> Template::process('Template=HASH(0x85546bc)','largemail.tt','SCALAR(0x893fb20)','SCALAR(0x893fac0)')
> called at newChkSize.pl line 90
>         main::gen_report() called at newChkSize.pl line 63
> 
> Rod
> --
>     "Open Source Software - You usually get more than you pay for..."
>      "Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL"
> 
> 
> 
> 
> _______________________________________________
> templates mailing list
> templates@xxxxxxxxxxxxxxxx.xxx
> http://lists.template-toolkit.org/mailman/listinfo/templates
> 


        -- 
        jeffa

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] Lost in Templation
Roderick A. Anderson 01:15 on 17 Jun 2004

Re: [Templates] Lost in Templation
Mark Mills 01:51 on 17 Jun 2004

Re: [Templates] Lost in Templation
Roderick A. Anderson 18:20 on 17 Jun 2004

Re: [Templates] Lost in Templation
Roderick A. Anderson 20:23 on 17 Jun 2004

Re: [Templates] Lost in Templation
Jeff Anderson 01:44 on 18 Jun 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52