First, some background.

There are several fundamentally different ways in
which a perl script can be run, including:

    1. At a shell prompt / command line.
    2. As a CGI

(there are various others.)

Each of these has its own "environment" in which
a running script runs.

These environments share some general things in
common, including:

    1. Environment variables
    2. Standard input and output streams.

But, while they all have these things, they all have
these things be different.

For example, if you run a script from the shell prompt,
the environment variables will be the ones apropos to
the shell prompt. When you run a script as a CGI, the
environment variables will be ones setup by the web
server (things like HTTP_REFERER etc.)

When you run a script from a shell prompt, the standard
input usually starts out connected to the keyboard and
standard out starts connected to the display.

When you run a script as a CGI, standard input
starts out connected to a faked up file that contains
the parameters (if any) passed to the script. (And
standard output is sent to the server which fiddles
with it then sends the fiddled version on to the
browser that asked for the URL in the first place.)

So, if this is invoked as a CGI, then

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body>";
print "what is your name? ";
$name = <stdin>;        # pulls data from CGI parameters
chomp ($name);
print "hello, $name!\n";
print "</body></html>";

Instead, you need to get in to use of html forms.
More generally, I recommend you take the time
to learn CGI.pm and start your scripts with:

    use CGI;
    use CGI::Carp qw(fatalsToBrowser);

That said, what you did makes so much sense its
tempting to imagine a pragma that makes it do
something sensible, ie

    use CGI::Lazy;

means the <stdin> is converted to a form call, and...
well, it gets complicated fast. So maybe not.

Reply via email to