Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Answer: What is a good "Press any key to continue" code?

( #33567=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > What is a good "Press any key to continue" code? contributed by tye

{ local( $| ) = ( 1 ); print "Press <Enter> or <Return> to continue: "; my $resp = <STDIN>; }

Comment on Answer: What is a good "Press any key to continue" code?
Download Code
RE: Answer: What is a good
by Fastolfe (Vicar) on Sep 22, 2000 at 01:35 UTC
    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.
      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

        I voted this down because I see no reason to accuse anyone of having a confused mind. Even just stating that you think that someone may have been confused should be done with some tact.

        I assume the personal attack was not intentional, hence I felt it should be brought to your attention.

        I also see no reason to tie writing to STDOUT with reading from STDIN. A very standard practice is to "read from @ARGV" and write to STDOUT (one used by many Unix commands and one that Perl has even devoted a command-line option to). Perhaps you meant "if you write a prompt to STDOUT..."?

                - tye (but my friends call me "Tye")
RE: Answer: What is a good
by tye (Cardinal) on Sep 22, 2000 at 01:43 UTC

    Note that getting any key to work is hard to do portably, so I just suggest you avoid the issue. Also <> is not the same as <STDIN> if there is anything in @ARGV.

            - tye (but my friends call me "Tye")
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-08-20 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls