in reply to Re: Puzzling CGI behavior
in thread Puzzling CGI behavior

thanks for the suggestion. I will take it. However, here's my question. Why does this happen? I mean, I can also do something like
my $template = param('template'); my $minscale = param('minscale'); my %webobj = ( 'template' => $template, 'minscale' => $minscale );
and then I get acceptable behavior. But, this shouldn't be necessary. In fact, even if I get something strange, why the heck does 'template' => param('template') end up grabbing 'minscale' as its value... that comma after param('template') should tell it to lay off of 'minscale'. Would love to find out why? Many thanks

Replies are listed 'Best First'.
Re: Re: Re: Puzzling CGI behavior
by chromatic (Archbishop) on Jan 30, 2003 at 03:27 UTC
    that comma after param('template') should tell it to lay off of 'minscale'.

    It doesn't, though. merlyn has the right of it, as usual. There are no parameters. Calling param() in list context (as happens in the hash assignment) produces an empty list in this case. Since there has to be a value, Perl grabs the next one in a list.

    Your snippet is equivalent to:

    my %webobj = ( 'template', param( 'template' ), 'minscale', param( 'minscale' ), );

    Consider what happens if you assign an empty list:

    use strict; use Data::Dumper; my %hash = ( foo => ,,, bar => 1 => 'baz' ); print Dumper \%hash;