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

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.

Replies are listed 'Best First'.
RE: RE: Answer: What is a good
by merlyn (Sage) on Sep 22, 2000 at 01:55 UTC
    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")
        I think you are being too sensitive.

        When merlyn says, If you prompt to STDOUT, I think most people (OK I do) will read that as, If you print an interactive message to STDOUT, which is what was meant.

        Furthermore the phrase ...in general indicates a confused mind... does not say that Fastolfe in particular has a confused mind. It just says that this kind of mistake is symptomatic of a confused mind. Which it is. If you do not understand how <> differs from <STDIN>, that indicates confusion! Even worse, if you meant that you expect files in @ARGV to correctly hold responses to interactive commands in a script you are still changing, that indicates dangerous programming practices!

        All of which goes to say that even though I had let merlyn's post pass before, I voted ++ to counteract your -- because I thought your reasoning was not very good.

        UPDATE
        I have been told that "prompt" was originally "print", which shows why - particularly when a point has caused comment - it is good to make it clear that there was an edit.