Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Do not use diamond for STDIN

by merlyn (Sage)
on May 02, 2001 at 17:58 UTC ( [id://77318]=note: print w/replies, xml ) Need Help??


in reply to Loop Control : REDO

Besides the points made in Re: Loop Control : REDO, you should never use the diamond with interactive I/O like prompting. Use <STDIN> instead. Otherwise, your day will be very miserable when someone types a filename on the command line. You'll still get all those prompts, and it'll look very funky.

As an alternative, say print ... if $ARGV eq '-', then you'll only be prompting if you're actually reading from STDIN. The output-only results printing can be unconditional.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Do not use diamond for STDIN
by Fatty Lumpkin (Acolyte) on Oct 29, 2001 at 20:48 UTC
    Sir,
    It seems like this may be a very desireable action at times. EG. in the case where you want a script to be interactive, but also have it cronned with all of the values for it in another file. In which case <> will do exactly what you want in both cases. Isn't this more a question of style that what SHOULD/SHOULDN'T be done?

    -Fatty Lumpkin

    Update: Merlyn is 1000% correct, poor reading on my part, i missed the actual printed prompt.I am just used to doing something like
    shift || (print "\nprompt:" and <>);

    But that doesn't allow for this behavior either.I missed the point, Thanks for correcting me.
      It seems like this may be a very desireable action at times. EG. in the case where you want a script to be interactive, but also have it cronned with all of the values for it in another file. In which case <> will do exactly what you want in both cases.
      In which case, you don't want to prompt, because then you get a bunch of prompts in the output, without responses. That... looks... tacky. I'd fatal that in a code review.

      -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://77318]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-18 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found