in reply to Using associate with HTML::Template

That code seems to work for me:
use CGI; my $q = CGI->new; use Data::Dumper; %cgi_vars = ( a => 1, fname => '', ); my $q = CGI->new(); ## This worked if ($cgi_vars{fname}) { $q->param('fname' => $cgi_vars{fname}); } else { $q->param('fname' => ""); } print Dumper($q->param('fname')); $q = CGI->new; ## But this did not $q->param('fname' => $cgi_vars{fname}); print Dumper($q->param('fname')); __END__ $VAR1 = ''; $VAR1 = '';
Are you sure you're testing the values correctly? Remember that param('something') returns an empty list in list-context (not undef) if there is no parameter named 'something'.

Replies are listed 'Best First'.
Re^2: Using associate with HTML::Template
by nedals (Deacon) on Apr 06, 2005 at 22:12 UTC

    Thanks for the response. A test, using something similar, indeed works.
    It turns out that I had a different problem..
    $cgi_vars{fname} was indeed being set to "", but later in the script it was re-set to an 'undefined' value. This, of course, was not readily discernible in my test print statements.

    So this returned the original value if the $cgi_vars{fname} value is undefined.

    $q->param('fname' => $cgi_vars{fname});