Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: First time using Args

by JavaFan (Canon)
on May 03, 2012 at 17:13 UTC ( #968779=note: print w/ replies, xml ) Need Help??


in reply to First time using Args

You want to explicitly read from STDIN, not the magical ARGV, which only reads from STDIN if no argument are given (or to be precise, if @ARGV is empty). Replace your <> with <STDIN>.

And as a general advice: avoid write tools that ask the user questions: arguments are more flexible, as it makes piping and scripting easier. Imagine that each time you would run perl from the command line, it starts with:

$ perl Do you want to enable warnings? [y/N] n Do you want to loop over the input? [y/N] y You want to loop over the input. Print $_ each time? [y/N] ... 40 questions later ... Please type your one-liner, ending with a newline


Comment on Re: First time using Args
Select or Download Code
Re^2: First time using Args
by mmusser (Initiate) on May 03, 2012 at 17:34 UTC
    Fascinating. In Programming class, we were taught that <> = <STDIN>. I didn't know they were actually different. Thanks very much for your help :). I could write this without asking for user input...the only problem was that one of the args would be a string that may contain spaces, and I'm not sure how best to handle that. Make the user enter that argument with quotes?
      In Programming class, we were taught that <> = <STDIN>.
      That's wrong. <> is shorthand for <ARGV>.
      I could write this without asking for user input...the only problem was that one of the args would be a string that may contain spaces, and I'm not sure how best to handle that. Make the user enter that argument with quotes?
      Quotes, or backslashes should work in all shells that I know off. (The spaces are special to the shell, Perl has nothing to do with that).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-08-21 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (129 votes), past polls