You need to change your calculate sub to handle input as a 
hash-reference (example not tested).

sub calculate {

my %args = %{ $_[0] } if ref($_[0]) eq 'HASH';

return $args{a} + $args{b} if defined(%args);

}

These two documents might help you to better understand references.

man perlref
perldoc -f ref

-- Robin

Chakkit Ngamsom wrote:
>
> No help.
>
>  
>
> In  error log: Reference found where even-sized list expected at 
> [filename]
>
>  
>
> The result shows key as: HASH(0x2d5fe94), its value is blank.
>
>  
>
> Any idea?
>
>  
>
> Chakkit
>
>  
>
> *From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> *Sent:* Sunday, November 02, 2008 9:49 PM
> *To:* Chakkit Ngamsom
> *Subject:* Re: RE: [Templates] Passing hashes to Perl
>
>  
>
> Try sending them as references, within curly braces.
> ex:
>
> [% result({ one => "1", two => "2"}) %]
>
> See what happens...
>
>
>
>
> On Nov 2, 2008 9:42am, Chakkit Ngamsom <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> > Thanks Thompson,
> >
> >
> >  
> >
> >
> > I’ve tried it and no success.
> >
> >
> >  
> >
> >
> > Please note that I can get the results by trying:
> >
> >
> > [% result(“a”, "1", “b”, "2")
> > %] and [% result(“a”, 1, “b”, 2) %]
> >
> >
> >  
> >
> >
> > No need to specific VARIABLES. and double quotes are not matter
> > in this case.
> >
> >
> >  
> >
> >
> > I think there should be some blanket styles to handle this.
> >
> >
> >  
> >
> >
> > Thanks in advance,
> >
> >
> > Chakkit
> >
> >
> >  
> >
> >
> >  
> >
> >
> >
> >
> > From:
> > [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> >
> > Sent: Sunday, November 02, 2008 7:09 PM
> >
> > To: Chakkit Ngamsom
> >
> > Subject: Re: [Templates] Passing hashes to Perl
> >
> >
> >
> >
> >
> >  
> >
> >
> > It seems that your problem is with the dot operator.
> >
> > I think it should be:
> >
> >
> >
> > (in template)
> >
> > [% VARIABLES.result( a=>"1", b => "2") %]
> >
> >
> >
> > Also I believe you are "stringifying" the numbers by including the
> > double quotes.
> >
> > Try it winthout the double quotes.
> >
> >
> >
> > [% VARIABLES.result(a => 1, b => 2) %]
> >
> >
> >
> > Hope it helps!
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Nov 2, 2008 1:47am, Chakkit Ngamsom [EMAIL PROTECTED]> wrote:
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > Hi All,
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > Can someone please let me know how to pass hashes from
> >
> > > template to Perl?
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > I’d like to pass hashes to Perl subroutine to process things
> >
> > > then return the results back to template.
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > I tried something like this but it didn’t work:
> >
> > >
> >
> > >
> >
> > > [% result(a => ”1”, b => ”2”) %]
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > Perl TT config:
> >
> > >
> >
> > >
> >
> > > my $config = {
> >
> > >
> >
> > >
> >
> > >            
> > VARIABLES
> >
> > > => {
> >
> > >
> >
> > >
> >
> > >
> >                        
> > result
> >
> > > => \&calculate,
> >
> > >
> >
> > >
> >
> > >             },
> >
> > >
> >
> > >
> >
> > > };
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > Perl subroutine:
> >
> > >
> >
> > >
> >
> > > sub calculate {
> >
> > >
> >
> > > my (@args) = @_;
> >
> > >
> >
> > > return $args{a} + $args{b} if @args;
> >
> > >
> >
> > >
> >
> > > }
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > It’s working if I tried this but I’m not
> >
> > > preferred:
> >
> > >
> >
> > >
> >
> > > [% result(”a”, ”1”, “b”,
> >
> > > “2”) %]
> >
> > >
> >
> > >
> >
> > >  
> >
> > >
> >
> > >
> >
> > > Thanks,
> >
> > >
> >
> > >
> >
> > > Chakkit
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> >
> >
> >
> >
> >
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
>   


_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to