Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Error when passing AoH ref to HTML::Template

by kutsu (Priest)
on Aug 17, 2005 at 19:57 UTC ( #484566=note: print w/ replies, xml ) Need Help??


in reply to Error when passing AoH ref to HTML::Template

Firstly you don't need all those my $c =..., but the error is because you sent a hash not a hash reference (also print $template->output).:

sub validate { my @params = @_; my @warning; for ( @params ) { my %h = ( missing => $_); push (@warning, \%h ) unless $c->param($_); } if ( @warning ) { print $c->header; my $template = HTML::Template->new(filename => './templates/warnin +g.html'); #don't use die $! while testing HTML::Template has it's own error +handling $template->param( warnings => \@warning ); print $template->output(); exit; } }

"Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce


Comment on Re: Error when passing AoH ref to HTML::Template
Download Code
Re^2: Error when passing AoH ref to HTML::Template
by silent11 (Vicar) on Aug 17, 2005 at 20:03 UTC
    Thanks! I'll give your code a try.

    I didn't want to add the extra instance of CGI, but when I don't add the instance inside of the sub I get the following eror:

    Can't call method "param" on an undefined value at /var/www/cgi-bin/eb +ranch/assignment/process.cgi line 23.
    Any ideas?


    -silent11
    Spread Firefox

      Only create one $c. Then pass it to validate. CGI can get tempermental when you keep creating new ones.

      #!/usr/bin/perl use strict; use HTML::Template; use MIME::Lite; use CGI; use CGI::Carp qw/fatalsToBrowser/; use Data::Dumper; my $c = new CGI; validate($c, qw/ email phone/ ); print $c->header,$c->start_html('everythings ok'); sub validate { my $c = shift; my @params = @_; my @warning; for ( @params ) { push (@warning, { 'missing' => $_ }) unless $c->param($_); } if ( @warning ) { print $c->header; my $template = HTML::Template->new(filename => './templates/warnin +g.html'); $template->param( warnings => \@warning ); print $template->output(); print Dumper @warning; exit; } }

      ___________
      Eric Hodges

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://484566]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-12-29 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls