relayeddeaction has asked for the wisdom of the Perl Monks concerning the following question:
Very new to Perl here..so excuse my lack of understanding on this fundamental.
Been screwing around with Perl on my computer for a few weeks.. finally decided to see if I could get a CGI script to manipulate data from a form. Can get the data from the query string (the form method is just GET, so I wasn't bothering to check if it's POST or GET...). Here's the code:
Not sure why, but only the last name/value pair are placed in the hash. for example, the form had 3 inputs. name, age, and word (for testing purposes..heh). upon submitting the form to the script with the values .cgi?Name=my+name&Age=12&Word=xyzzy ...checking the values in the scalar & the array, things come out fine. when checking the values in the hash, i only get... Word: xyzzy ...which would be the last things in the query string. Why this comes out this way I do not know. Maybe some else does? Like I said... Only been workign with Perl for a few weeks, and please excuse how verbose this is.print("Content-Type: text/html\n\n"); print("<HTML><BODY>"); $QSTRING = $ENV{'QUERY_STRING'}; $QSTRING =~ s/\+/ /g; print("<P align=center><B>(\$)QSTRING</B>: $QSTRING</P>"); # Split the $QSTRING by the ampersand and assign the parts to @QSTRING @QSTRING = split(/&/,$QSTRING); # Check the values in @QSTRING print("<P align=center><B>(@)QSTRING</B>:"); foreach $QSPart(@QSTRING) { print(" $QSPart"); } print("</P>"); foreach $Part(@QSTRING) { %FormData = split(/=/, $Part); } # Attempt to print out the names and values of the QSTRING.... @InputNames = keys(%FormData); foreach $InputName(@InputNames) { print("<P align=center><B>$InputName</B>: $FormData{$InputName}</P +>"); } print("</BODY></HTML>");
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A Beginner Apparently Sucks With Hashes...
by CheeseLord (Deacon) on Jul 22, 2001 at 10:28 UTC | |
by CharlesClarkson (Curate) on Jul 22, 2001 at 11:19 UTC | |
Re: A Beginner Apparently Sucks With Hashes...
by tachyon (Chancellor) on Jul 22, 2001 at 11:26 UTC | |
Re: A Beginner Apparently Sucks With Hashes...
by dragonchild (Archbishop) on Jul 23, 2001 at 17:40 UTC |
Back to
Seekers of Perl Wisdom