in reply to Prompting user input (newbie)

If the script is running from the command line, you can use something like the following:
#!/usr/bin/perl -w use strict; print "Enter something: "; my $response = <STDIN>; print "You entered: $response";
If you don't want the newline on the end of $response, don't forget to chomp it.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: Prompting user input (newbie)
by lauragarcia (Acolyte) on Apr 26, 2001 at 22:44 UTC
    Thanks, OvidinExile!
    You've just confirmed my basic problem: I'm running this program off the browser and it seems I need to be running directly from the command line. Where are the instructions for command-line running? The only way I knew to operate was with a Perl/CGI script through my browser.
    (I've just downgraded myself to Newbie minus minus.)
    Thanks for your patience...
    laura

      lauragarcia wrote:

      I'm running this program off the browser and it seems I need to be running directly from the command line.

      I'm not sure I follow you. Is this supposed to be a CGI script? Is this a program someone else wrote and you are using?

      If it's a relatively short program, perhaps you can post it here? Or perhaps you know enough to identify the relevant section of code and you can post that here? If so, be sure to wrap it in <CODE></CODE> tags so that the formatting is preserved.

      The reason I can't answer your question directly is due to lack of information. If it's a CGI script, I need to give you information about using CGI.pm to get the data. If it's a command line program, is it expecting command line arguments or does it want to read the data from STDIN? Seeing the appropriate code sections can give us better insight as to your needs.

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

        I was just trying to get an input line and capture the input as a string in a simple little CGI script. I only know a little about CGI scripts, and don't know about command line programs. Obviously the following bit of code doesn't have the means to accept input:
        #!/usr/bin/perl use CGI qw/:standard/; $q=new CGI; print $q->header; print "Enter something: "; my $response = <STDIN>; print "You just entered: $response";
        So my question is two-fold: Can a CGI script accept user input other than from an HTML-based form? Secondly, how might I find out about command line program functionality? Laura