in reply to Testing for the existence of STDIN?

This is expected behaviour. If you ask for something, Perl waits until it gets it. Your alternative is to pass arguments to the script, like the name of a file to open. If the file is empty, then you could exit cleanly.

UPDATE:
Actually, you _could_ use a time out with $SIG{ALRM}:

$SIG{ALRM} = sub { die 'STDIN' }; eval { alarm(1); print while <>; alarm(0); }; print "no STDIN\n" if $@ =~ /STDIN/;
You cannot get finer grained than one second with this way, but you can with select.

Or .... just use wog's much more elegant solution. wog++

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Testing for the existence of STDIN?
by darkomen (Acolyte) on Jan 24, 2002 at 03:05 UTC
    I have a piece of working code using sigalrm, i was just hoping there was more of a clean way to do so... It would be nice if you could use the -s test operator on STDIN...