There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
In the Unix world (where Perl was born) everything is a file. To send a prompt to a user, you print to STDOUT. To read input from the user you read from STDIN. By default, STDOUT will go to the user's terminal/window and STDIN will come from their keyboard. If you write your code using these assumptions then people will be able to redirect stuff into your scripts or redirect the output. They will be able to do things you never imagined. So, to read a line of input: my $line = <STDIN>;Or just: my $line = <>;Don't forget to chomp($line) to get rid of the trailing newline. To prompt the user: print "Enter a number: ";You may need to set $| to have the prompt appear instead of being held up in a buffer. Hope you get a good grade. Update: I forgot to mention that if you really need to read from the keyboard (say one character at a time without waiting for enter) then look into Term::ReadKey In reply to Re: Input/Output through the Keyboard
by grantm
|
|