You're somewhat right -- CGI forms can get input from STDIN, but they only get the content that's been sent to them. (you'd normally get this data from a form submission with method='POST') There is also data that's passed in through $ENV{'QUERY_STRING'}, which you'd get if you used a form with method='GET', or if you encoded it manually into a URL, such as:

http://server/path/script?param1=value1a;param1=value1b;param2=value2

For older CGI scripts, you'll have to use amperands instead of semicolons to seperate the key/value pairs, but you then have to encode them in the HTML, like so:

http://server/path/script?param1=value1a&param1=value1b&param2=value2

To make things even more confusing, you can also pass things in through $ENV{'PATH_INFO'}, by giving a URL with path information past the script, like so

http://server/path/script/arg1/arg2/arg3

(You don't have to seperate the arguments with slashes -- I don't think there's a set convention for that one)

But, it gets worse when you consider that you could declare a form with

<form action='http://server/path/script/PATH_INFO?QUERY_STRING' method='POST'>

which would result in three different sources of input. And let's not forget that you could also pass extra input in the HTTP headers.

So, what's the solution to all this? Well, use CGI or use CGI::Lite would probably be the easiest, and let them do all the work:

use CGI::Lite; my $cgi = new CGI::Lite; my %input = $cgi->parse_form_data();

Update : missing a 'my'. Doh.


In reply to CGI input by jhourcle
in thread My cgi nonsense. by tgolf4fun

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.