http://www.perlmonks.org?node_id=464183

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!

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.