Re: What is a good "Press any key to continue" code?⭐
by tye (Sage) on Sep 22, 2000 at 01:34 UTC
|
{
local( $| ) = ( 1 );
print "Press <Enter> or <Return> to continue: ";
my $resp = <STDIN>;
}
| [reply] [d/l] |
|
That isn't quite "any key", but that's what I was going to say also...
print "Press ENTER to continue: ";
<STDIN>;
# continue...
Update: Thanks to everyone for pointing out my <> v. <STDIN> flaw. When building quick/easy scripts for myself I tend to get lax and use <> when the correct way to reference a line from STDIN is <STDIN>. A bad habit I guess. | [reply] [d/l] [select] |
|
No. Never use <> when you mean <STDIN>.
What if you're using the elements of @ARGV to hold keywords
or other items?
I'd fail this one in code review, since it has a trivial fix,
could cause significantly odd behavior,
and indicates a confused mind in general.
My code-review rule is:
if you prompt to STDOUT, you should read from STDIN,
not ARGV.
-- Randal L. Schwartz, Perl hacker
| [reply] [d/l] [select] |
|
|
|
|
| [reply] [d/l] [select] |
Re: What is a good "Press any key to continue" code?⭐
by Anonymous Monk on Sep 22, 2000 at 06:38 UTC
|
use Term::ReadKey;
ReadMode 4; # Turn off controls keys
while (not defined ($key = ReadKey(-1)) {
# No key yet
}
print "Got key $key\n";
ReadMode 0; # Reset tty mode before exiting
| [reply] [d/l] |
Re: What is a good "Press any key to continue" code?⭐
by Anonymous Monk on Nov 14, 2003 at 20:07 UTC
|
For windows based systems:
system( 'pause' );
| [reply] [d/l] |
Re: What is a good "Press any key to continue" code?
by mancz (Initiate) on Mar 21, 2002 at 16:58 UTC
|
print 'press [Enter] to continue...'; <>;
Originally posted as a Categorized Answer. | [reply] [d/l] |
Re: What is a good
by Anonymous Monk on Nov 18, 2002 at 15:01 UTC
|
| [reply] |
Re: What is a good
by Anonymous Monk on Nov 18, 2002 at 15:00 UTC
|
print "Press Enter to continue ";
<STDIN>;
Originally posted as a Categorized Answer. | [reply] [d/l] |
Re: What is a good
by Anonymous Monk on Sep 22, 2000 at 06:38 UTC
|
use Term::ReadKey;
ReadMode 4; # Turn off controls keys
while (not defined ($key = ReadKey(-1)) {
# No key yet
}
print "Get key $key\n";
ReadMode 0; # Reset tty mode before exiting
Originally posted as a Categorized Answer. | [reply] [d/l] |