develooper Front page | perl.beginners | Postings from January 2002

RE: What's wrong with this?

From:
Jeff 'japhy' Pinyan
Date:
January 29, 2002 06:15
Subject:
RE: What's wrong with this?
Message ID:
Pine.GSO.4.21.0201290910490.27903-100000@crusoe.crusoe.net
On Jan 29, Gary Hawkins said:

>> If you want to loop over all the form fields, you'd do:
>>
>>   for $field (param()) {
>>     print "$field => ", param($field), "<br>\n";
>>   }
>
>How can the param's be placed into a new hash?

CGI.pm has a Vars() method, I believe, which returns a hash.

  use CGI;
  my $q = CGI->new;
  $data = $q->Vars;

  print $data->{field};  # etc.

But note that this can cause annoyances when you have multiple fields of
the same name (like checkboxes).  The values will be \0-separated.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About