Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

by tye (Sage)
on Sep 22, 2000 at 01:34 UTC ( #33567=categorized answer: print w/replies, xml ) Need Help??

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

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

Replies are listed 'Best First'.
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 (Sage) 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?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2018-06-20 19:35 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.