in reply to Problem with CGI::Vars

See the CGI documentation.

In a hash, you cannot have two entries with the same key. Hence, if your form returns multiple values for the same key, CGI will return a list of values for that key when you call param.

hope that helps.

Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd

Replies are listed 'Best First'.
Re: Re: Problem with CGI::Vars
by tachyon (Chancellor) on Feb 08, 2003 at 13:30 UTC

    FWIW with Vars() it returns a \0 (null) separated string for multiple values with the same param name (hash key) which was the cgi-lib.pl way or doing it. This is a compatibility method that should not really be used. As you point out all that has to be done is:

    use CGI; my $q = new CGI; # iterate over all param names for my $param ( $q->param() ) { print "<p>Param $param\n"; # iterate over all values for param name $param for my $value ( $q->param($param) ) { print "<br> value: $value"; } }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Hello.

      Done that foreach param() stuff, it shows the same as $q->Vars(), ie still not doing the right thing.

      Thanks
      Sawan

        As suggested by me at Re: Re: Re: Problem with CGI::Vars show the HTML and Data::Dumper example output.

        For what it is worth it is a computer. It always does the right thing. You're problem is that you think you are telling it one thing but you are not.

        Show the requested output and your HTML or there is nothing we can do to help.

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: Problem with CGI::Vars
by sawanv (Novice) on Feb 08, 2003 at 08:59 UTC
    Hello.

    The form does not have multiple keys. The name of the form parameter is composed of two things: an ipaddress and a parameter name. Thus no two fields are alike. Have verified that by "view source".

    What else could it be? Why should the form return a single parameter name when all are unique?

    Thanks, Sawan.

      You don't seem to understand the explanation given. Please show your HTML. For debugging I suggest you look at the CGI object like this which will confirm the data received:

      #!/usr/bin/perl use CGI; use Data::Dumper; my $q = new CGI; print $q->header(), '<pre>', $q->escapeHTML(Dumper $q), '</pre>'; # this will give you all the values of the checkboxes # called param_name that were checked separated by spaces print join ' ', $q->param('param_name');

      This will show you exactly what your script is getting.

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print