PDA

View Full Version : Trouble isolating a variable item.


Arthur
04-01-2006, 07:24 PM
I'm not very familiar with perl and was hoping to get some help with a little problem I had:

I have a form that passes information to a processing script that forwards info to the following user output script:

###########################################

my $cgi = CGI->new();
my @param = $cgi->param();
print"Content-type: text/html\n\n";
for(@param)
{
my @arr = $cgi->param($_);
print"$_:".join(':',@arr)."<br>";
}

###########################################

This script outputs the formfield name and the value. What I wanted to do was isolate specific form values for additional processing.

I was able to isolate the form names buy simiply stating:

##########################################
print"".$param[0]."";
##########################################

but can't isolate the value in the @arr array.

Any solutions...?

KevinADC
04-02-2006, 12:29 AM
You should really be getting the individual form fields by their respective name in the form, say a form field is named "comments" in the form:

my $comments = $cgi->param('comments');

now $comments has whatever value was passed from the form field "comments" to the script. You can also call the list as a hash instead of an array and use the form field names to get the form data:

my %form = $cgi->Vars;

now $form{'comments'} would be the same as $comments above. It's all documented in the CGI.pm documentation:

http://perldoc.perl.org/CGI.html

Arthur
04-02-2006, 04:43 AM
Thanks for your response Kevin - very appreciated.

I'll look into applying that info to the script and moreover read through that link you sent.