ecuguru has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I've got code below (copy/pasted) that works for grabbing data from a post/get request.
Can someone tell me what function I can use to check to see if a value was submitted or not? I have played with exists and defined, but couldn't get either to work right.
A user can post and id and another number. If the number isn't provided, I have a default number that I replace it with later. But I can't figure out how to tell perl that if the value isn't submitted, tell me.
Any ideas? And Thanks in advance!
I've got code below (copy/pasted) that works for grabbing data from a post/get request.
Can someone tell me what function I can use to check to see if a value was submitted or not? I have played with exists and defined, but couldn't get either to work right.
A user can post and id and another number. If the number isn't provided, I have a default number that I replace it with later. But I can't figure out how to tell perl that if the value isn't submitted, tell me.
Any ideas? And Thanks in advance!
if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { print "Content-type: text/html\n\n"; print "<P>Use Post or Get"; } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg; $value =~s/<!--(.|\n)*-->//g; if ($formdata{$key}) { $formdata{$key} .= ", $value"; } else { $formdata{$key} = $value; } } $id = $formdata{'id'}; $num = $formdata{'num'}; #If there great, if not how do i know? $num = sprintf("%3.3f",$num); #if num is not present, this makes num +0.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is $formdata present?
by blazar (Canon) on Jun 07, 2005 at 08:46 UTC | |
Re: Is $formdata present?
by stonecolddevin (Parson) on Jun 07, 2005 at 09:59 UTC | |
Re: Is $formdata present?
by tchatzi (Acolyte) on Jun 07, 2005 at 08:49 UTC | |
by Anonymous Monk on Jun 07, 2005 at 09:03 UTC | |
by techcode (Hermit) on Jun 07, 2005 at 22:05 UTC | |
by ruoso (Curate) on Jun 07, 2005 at 18:33 UTC | |
by ecuguru (Monk) on Jun 07, 2005 at 17:45 UTC | |
by Anonymous Monk on Jun 07, 2005 at 09:08 UTC | |
Re: Is $formdata present?
by jpeg (Chaplain) on Jun 07, 2005 at 09:11 UTC | |
by ecuguru (Monk) on Jun 07, 2005 at 17:40 UTC |
Back to
Seekers of Perl Wisdom