http://www.perlmonks.org?node_id=33567


in reply to What is a good "Press any key to continue" code?

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

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