in reply to Warn if STDIN pipe is missing or unwanted

Why? If feels to me to go against the *NIX principles to worry about something like that. Perhaps this is an X/Y Problem, so if you could explain why you need this that would be useful.

If you need enough rope to shoot yourself in the foot, perhaps there's some trickery you can try like fileno(*ARGV)==fileno(*STDIN) or something, though I don't give any guarantees on that being reliable either. Also see IO::Interactive.

Replies are listed 'Best First'.
Re^2: Warn if STDIN pipe is missing or unwanted
by Anonymous Monk on Jan 11, 2026 at 09:40 UTC
    Because different commands have different syntaxes/semtantics and after running other commands, I sometimes use the wrong syntax on the script in question. When that happens the script can either exit without processing the onput or hang waiting for input. Both cases seem like an error to me and if possible, should warn or fail.
      I sometimes use the wrong syntax on the script in question.

      In that case perhaps the simplest solution is to require the -i option in your script, thereby always requring one to specify a filename or "-"?

        That doesn't address the issue of accidentally running ./script.pl -i - without an input source for STDIN. That seems like an error to me. Making '-i' required also would preclude allowing input exclusively from @ARGV. I modeled the UI somewhat on wget/aria2c/(and very recently curl), where you can pass a few inputs in @ARGV, but can pass an input file for larger batches. Of course the simplest answer is to only allow input from @ARGV and use xargs to feed from other input sources, but that results in less ease of use.