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:
comparing string

 



zsadal
New User

Aug 24, 2005, 2:37 AM

Post #1 of 2 (1494 views)
comparing string Can't Post

HI,

I am a newbee to perl. I am having a very basic problem and i cannot find where i am doing

the thing wrong.

I want a user to enter a single character on the console, and then i want to check that

character and do different things depending on the input. Its something like a Y/N question

thing. Any idea....

Regards


rork
User

Aug 24, 2005, 4:11 AM

Post #2 of 2 (1491 views)
Re: [zsadal] comparing string [In reply to] Can't Post

The solution is somewhere in the perl faq but here's some code.
you have to use Term::ReadKey


Code
use strict; 
use warnings;
use Term::ReadKey;

ReadMode('cbreak');

my $response = ReadKey(0);
# checks if response is y or n
while ($response !~ m/[yn]/i) {
$response = ReadKey(0);
}
print $response . "\n"
if (lc($response) eq 'y') {
# do something
}

Code
-- 
Don't reinvent the wheel, use it, abuse it or hack it.

 
 


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

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