in reply to Re: Function-oriented style CGI accessing form parameters
in thread Function-oriented style CGI accessing form parameters

Thanks. The Data::Dumper bits threw me at first, but since I don't have that module, I'll just ignore those lines.

I assume (dangerous, I know), that I can print the key value pairs with:

while (my ($variable_name, $variable_value ) = each %params) { print "Variable name = $variable_name/n Variable value = $variable +_value\n\n"; }

Yes?

UPDATE
my test/understanding code now looks like this:

#!/usr/bin/perl -wT # tools.cgi use strict; use CGI qw(header start_html Vars pre); use CGI::Carp qw(fatalsToBrowser); print header(); print "These are the values submitted:\n\n"; my %params = Vars(); my $count = keys %params; print $count; while (my ($variable_name, $variable_value ) = each %params) { print "Variable name = $variable_name/n Variable value = $variable +_value\n\n"; }
I tried
use CGI qw(:standard :cgi-lib); and
use CGI ":standard"; and both of those threw errors and wouldn't execute. But this third option will run, but gives an output of
These are the values submitted: 0
even though I know there are values. I passed and printed them successfully with
foreach $sri_variable( $cgi->param){ print "$sri_variable:\n"; foreach $variable_value( $cgi->param($sri_variable) ){ print " $variable_value\n"; } }

Replies are listed 'Best First'.
Re^3: Function-oriented style CGI accessing form parameters
by Your Mother (Archbishop) on Aug 03, 2005 at 20:49 UTC

    Sounds like you're doing something weird in there; you should probably check your error logs or do the full use CGI::Carp qw(fatalsToBrowser warningsToBrowser);. All those examples should work fine.

    Another thing you might consider is the Vars() idiom is a little strange today. There is no reason to avoid the param() function in favor of it. Your code above becomes (with a little HTML formatting help):

    print '<ul>'; for my $sri_variable( param() ) { print '<li>', $sri_variable; print '<ul>'; for my $variable_value( param($sri_variable) ){ print li($variable_value); } print '</ul></li>'; } print '</ul>';

    Make sure to use strict; use warnings; too. It looks like you're not. (update: fixed bad HTML nesting.)

      I usually use it, but it had gotten left out this time, so I put the use CGI::Carp qw(fatalsToBrowser warningsToBrowser); in and ended up with "begin failed--compilation aborted at /actapps/suitespot/cgi-bin/sri/tools.cgi line 9."

      Line 9 is the CGI::Carp line.

      LOL.
      I just can't win today.