in reply to STDIN refuses input

Greetings, lcole.

Like perhaps most of the responses thus far. It isn't very clear what it is you are hoping to achieve with the script you've posted. Your script, as it is, won't work. If I understand your intended implementation. If I were to guess. I'd think you wanted to simply post a clever reply to someone who has perhaps entered their name in a web page you have on your web site (hosted, not on your own computer). As such, you might well modify your script above to look something like this

#!/usr/bin/perl -w use strict; use CGI qw/:standard/; my $input = param("input")||""; print "content-type:text/html; charset=utf-8\n\n"; print qq(<!DOCTYPE html><head></head><body> <form method="post" action="realname.pl"> <label for="input">What is your name: </label><input type="text" name="input" value="" /> <input type="submit" value="Post Input" />); if ($input) { print qq(<br />Hello, $input<br />); }else{ print qq(<br /><br />); } print qq(</form></body></html>);
Give it a try, and see if it's what you were hoping to achieve. If it's not. I'm afraid you'll need to be a bit more specific as to your intended goal.

Best wishes.

--Chris

Yes. What say about me, is true.

Replies are listed 'Best First'.
Re^2: STDIN refuses input
by lcole (Initiate) on Dec 16, 2013 at 20:04 UTC

    Well, I said I am a beginner, and it certainly shows as I do not understand many of the comments. Let me try again.

    I copied three sample Perl scripts from the Web, because I wanted to know how to install them on my host's system. Two of three scripts were put into my host's CGI-BIN and worked perfectly. The other script was also installed and works to a point.

    It is a simple script and I expected it would ask for input through <STDIN> and save the input in a $variable. The script would then immediately print "Hello, $variable." I am sure that <STDIN> does not wait for input and prints the incomplete hello message without the $variable.

    From what I understand, I could achieve this test with only my local computer. That is not what I need. I got the installation correct, I think, but I am missing something. Perhaps the script I copied is meant for a local computer.

    Ultimately, I have some pre-written scripts that I want to use, and I need to know how to modify them for my site, and install them.

    What will it take to make my simple script work correctly? As soon as it works, I will go on to learn something more difficult.

    Thanks to all.

    lcole

      Greetings, lcole.

      If I understood you correctly, I've already given you pretty much what you asked for; Take input from a web page, and respond to said input.

      There are other possible variations. The way I chose to present it, was what I thought might be easiest to follow, and seemed closest to the example you presented.

      From the looks of it (your script), it seems pretty old, in style. Usually taking input from <STDIN> is chosen when you are at a console, or tty/terminal (at a local computer -- within a shell). You can still use that same process within a web page. Something like

      read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
      But it can get pretty hairy. Because you must take additional measures to "sanitize" your input. To prevent users from entering shell commands like rm -rf /. Which could effectively delete your(hosters) file system. The commands are only limited to what is available with your hosting account, or how clever the user is, that uses your (unsanitized) input. So given that you indicate that you're fairly new to Perl. I would strongly advise against taking the <STDIN> approach. At least until you become more comfortable with Perl. But by then, I suspect you'll see that's it's probably more work than it's worth. Just to say you did it with <STDIN> :)

      Hope this helped, and best wishes.

      --Chris

      Yes. What say about me, is true.