Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Do not use diamond for STDIN

by merlyn (Sage)
on May 02, 2001 at 17:58 UTC ( #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


Comment on Do not use diamond for STDIN
Select or Download Code
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
Node Status?
node history
Node Type: note [id://77318]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-11-28 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (199 votes), past polls