in reply to Puzzling CGI behavior

my %webobj = ( 'template' => param('template'), 'minscale' => param('minscale') );
That's always dangerous code. param in a list context (or any subroutine in a list context, for that matter) might return a variable number of arguments. You'll want to add scalar in front of each of those param calls.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Puzzling CGI behavior
by Cody Pendant (Prior) on Jan 30, 2003 at 03:50 UTC
    You get exactly the same result if you do this:
    my %webobj = ( 'template' => , 'minscale' => 2 );
    because there is no param(template), so it's like you said 'template' => nothing, comma, minscale, I guess.

    I suppose this is somehow different to doing it with an undefined variable -- that way you'd get undef as the value for 'template'.

    I know it's daggy and old-fashioned, but if I'm in a hurry, I just do this:

    CGI::ReadParse();
    which puts everything into a hash called %in. That was only included in CGI.pm for backward, perl 4/cgi-lib compatibility, but I like it. It does what you're trying to do here, right?
    --
    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D
      I often do:

      use CGI qw(:cgi-lib); my $form = Vars;

      Gives you a tied hash-reference to all parameters, also allowing you to change the submitted parameters...

Re: •Re: Puzzling CGI behavior
by punkish (Priest) on Jan 30, 2003 at 03:39 UTC
    thanks, that also works... so my choices are
    my %webobj = ( 'template' => param('template') || '', 'minscale' => param('minscale') || '' );
    or
    my %webobj = ( 'template' => scalar(param('template')), 'minscale' => scalar(param('minscale')) );
    From Randal's comment it seems the latter would be the wiser choice.

    I am assuming 'minscale' is being assigned as a value to the 'template' key because there is nothing in param('template') and the comma is causing minscale to appear as part of a list.