CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
command line like interface?

 



lostChild
stranger

Mar 31, 2001, 8:47 AM

Post #1 of 4 (219 views)
command line like interface? Can't Post

this hasn't much to do with cgi.... but can someone tell me how to constuct a simple program which prompts the user to type in something and whatever is typed is placed into a scalar variable....
please?



Jasmine
Administrator / Moderator

Mar 31, 2001, 9:45 PM

Post #2 of 4 (212 views)
Re: command line like interface? [In reply to] Can't Post

It doesn't have to be CGI to be a valid Perl question Smile

Code
#!/usr/bin/perl 

print 'Please enter your name and hit enter: ';
my $name = <>;
chomp $name;

print "Hello, $name\n";

The <> or <STDIN> causes the program to pause and await input from the user.

Hope this helps!



lostChild
stranger

Apr 1, 2001, 6:05 AM

Post #3 of 4 (209 views)
Re: command line like interface? [In reply to] Can't Post

i have a program when running this program:

it will not display "Please enter your name and hit enter:" until i have typed in something.......



Jasmine
Administrator / Moderator

Apr 1, 2001, 9:18 AM

Post #4 of 4 (207 views)
Re: command line like interface? [In reply to] Can't Post

Are you certain that you copied it correctly?

The print statement comes before the <> line, so Perl will execute that first. I've just tested it on both Win98 and Linux, and it works as intended (question before needing to hit enter)


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives