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:
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("&nbsp;$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>");
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.

In reply to A Beginner Apparently Sucks With Hashes... by relayeddeaction

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.