hrmm... your script fails horribly for me. It freezes after I type the first character. The 'Type fast:' prompt is also right-flushed on my terminal. Uncommenting your cygwin line fixes the right-flushed text, but that is a bad way to do it. $/ is best kept at "\n". Try using \015\012 instead of \r\n as well. "\r\n" and "\015\012" are not guaranteed to be the same value. So to beat the snot out of POE for once (and most likely only time) in my life heh:
#!/usr/bin/perl -w
$|++;
use strict;
my ($input, $failed);
STARTIT:
eval {
local $SIG{ALRM} = sub { die "timed out\n" };
print 'You have 10 seconds. Type fast: ';
alarm 10; chomp( $input = <STDIN> ); alarm 0;
};
if ($@) {
if ($@ eq "timed out\n") {
if (++$failed == 3) {
print "\nTimed out 3 times. You're toast!\n\n" and exit;
}
else {
print "\nTimed out. Try again!\n\n";
}
}
else {
die "Unhandled error: $@";
}
}
else {
print "You said '$input'. 10 more seconds now!\n\n";
}
goto STARTIT;
If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|