in reply to detect input available from command line

if ( @ARGV ) { while (<>) { } } else { # do something else }

Replies are listed 'Best First'.
Re^2: detect input available from command line
by mifflin (Curate) on Mar 10, 2011 at 21:51 UTC
    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?

      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().

      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.