manishrathi has asked for the wisdom of the Perl Monks concerning the following question:

When data is to be provided to perl script from HTML form, the data is provided in the form and upon "submit" the post method is used for taking data to server. Now, how is this data provided to perl script, by stdin ? what is meant by that ?

STDIN is from cmd prompt, right ? How does this data go to cmd prompt ? I was reading some sample script and it said that "read" cmd is used to read data from the stdin. What does this mean ? I have to provide "read" in the perl script and it will read the data of the form from cmd prompt ? How does the data of the form go to cmd prompt ?
thanks

Replies are listed 'Best First'.
Re: stdin in perl
by bv (Friar) on Sep 24, 2009 at 22:06 UTC

    STDIN is a file descriptor (file handle in Perl) that is usually connected to the keyboard input. In the case of a CGI script, HTTP POST data is fed to STDIN, so you can read it with readline or the <> operator. A much better way is to use a CGI module, such as the core CGI module.

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
Re: stdin in perl
by ww (Archbishop) on Sep 24, 2009 at 23:44 UTC
    Just in case it's needed, this addendum to bv's fine reply:

    No, the post data does NOT go to the command prompt. It goes to the file descriptor, STDIN, which is NOT solely a repository for data from a command prompt.

    Then, if you use CGI (read perldoc CGI), you don't have to worry about the info getting to the server; your visitor's browser sends it to the file handle STDIN at the server, whence Apache or other http server programs pass it to your CGI script. The script must process the data elements thus passed and generate information for the server to act upon (generalization: pass back to the browser as a new page).

Re: stdin in perl
by biohisham (Priest) on Sep 25, 2009 at 05:37 UTC
    You sound confused about filehandles, STDIN is nothing but a Perl filehandle which is a label that describes a connection to a file, Perl has many types of filehanldes, examples are the STDIN, STDOUT, STDERR, now the way these are different has to be obvious from their context after you read about them, there're technical differences as well that got to do with buffering for instance, And you can have your own filehandles introduced too.

    If you wanna learn following the right path then you might want to invest time in studying and reflecting, if you rely only on environmental impulses to motivate you you may well be laying the bricks on top of each other before they're hardened enough yet before you complete building and it'd come falling down on its weight.

    Anyhow here's a list that can be of use (just for starters):

    NB: filehandles are customary written in uppercase.
    Good Luck and Happy Perl journey.


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.