in reply to How to Test For Empty Piped Input

Untested, at start (see https://perldoc.perl.org/perlfunc#-X-FILEHANDLE):
BEGIN { die "No input given and STDIN is tty" if -t STDIN and !@ARGV }

Replies are listed 'Best First'.
Re^2: How to Test For Empty Piped Input
by hippo (Archbishop) on Sep 02, 2024 at 08:32 UTC

    Tested now (although not on MSWin32). Works as intended and doesn't even need the BEGIN block.

    #!/usr/bin/env perl use strict; use warnings; die "What no STDIN?\n" if -t; print while <>;

    Runs like this:

    $ ./stdintest.pl What no STDIN? $ echo foo | ./stdintest.pl foo $

    🦛