Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How do you simulate the use of the keyboard ?

by httptech (Chaplain)
on May 10, 2000 at 15:59 UTC ( [id://10933]=note: print w/replies, xml ) Need Help??


in reply to How do you simulate the use of the keyboard ?

Well, the keyboard is usually read using <STDIN> which is just another filehandle.

So say you have written a script that asks a few questions like:

print "What is your name? "; my $name = <STDIN>; chomp $name; print "What is your quest? "; my $quest = <STDIN>; chomp $quest; print "What is your favorite color? "; my $color = <STDIN>; chomp $color;
Now, if you want to test that out without actually having to type it into the keyboard, you can make a textfile like:
Anonymous Monk I seek the Wisdom of the Monastery Yellow...no, Blue! arghhhhhhhh!
Now, you can open that file in your program and assign it a filehandle <FOO>, ahead of where the questions are asked. Then, use a line like this: *STDIN = *FOO; (also before where you first start grabbing STDIN)

That allows you to alias STDIN to FOO and the file will be read instead of the keyboard while you are testing your program. When you're done testing, just remove the open statement and the *STDIN = *FOO line and you're all set.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://10933]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found