Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: detect input available from command line

by mifflin (Curate)
on Mar 10, 2011 at 21:51 UTC ( #892543=note: print w/ replies, xml ) Need Help??


in reply to Re: detect input available from command line
in thread detect input available from command line

What if the input is not coming from @ARGV but from stdin?
example:

$ ./testprog -t testing@testing.com -s test5 <<EOT; > stuff > typed > in > here > EOT
In this case @ARGV is empty but there is still something to read. How would I detect this?


Comment on Re^2: detect input available from command line
Download Code
Re^3: detect input available from command line
by Eliya (Vicar) on Mar 10, 2011 at 22:02 UTC

    You could test

    if (@ARGV or !-t STDIN and !eof()) { while (<>) { ...

    (but any non-input file arguments would need to be removed from @ARGV first, of course)

    This should work with input file arguments on the command line, heredoc input (<<), input redirect (<), and piping into the program (|).

    Update: actually, I think you don't even need the eof().

Re^3: detect input available from command line
by jwkrahn (Monsignor) on Mar 11, 2011 at 03:40 UTC

    I have a program that may try to get data from the command line using

    What if the input is not coming from @ARGV but from stdin?

    If the input is coming from STDIN then it is not on the command line.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2014-10-25 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls