Perl code to accept keyboard input : "prompt" or "ReadKey"

Posted by dlauxx on 2007-01-30 02:54

Tried to accept user response from keyboard like "Press any key to continue ..." type of thing.

perl code and the web page generated by perl:-

perl code

#!/usr/bin/perl -w
use CGI ':standard','-debug';
use ActiveState::prompt qw(prompt yes enter);

print header();
print start_html("Testing ReadKey or other");

print "This is to test the different responses from keyboard.";
$ans=prompt("Press any key to continue ... ",'yes');

print end_html();

Source Code generated

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" lang="en-US" xml?="en-US">
<title>Testing ReadKey or other</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
This is to test the different responses from keyboard.

The perl code was executed until the print statement and it stopped without error. Anyone has any idea about what is wrong? And can I use other code? I did try Term? but also failed.

Please help. Thanks.

ActiveState Staff
Thu, 2007-02-01 16:45

CGI makes use of stdin and stdout for its own purposes, therefore those modules will not work in CGI code. I recommend checking out:

For a dated but useful reference to the current CGI protocol. You can find sample scripts on the 'net by searching for "CGI script" in your favourite search engine.