perl-select

How can I check (peek) STDIN for piped data in Perl without using select?

冷暖自知 提交于 2019-12-09 09:14:11
问题 I'm trying to handle the possibility that no arguments and no piped data is passed to a Perl script. I'm assuming that if there are no arguments then input is being piped via STDIN. However if the user provides no arguments and does not pipe anything to the script, it will try to get keyboard input. My objective is to provide an error message instead. Unfortunately, select() is not portable to some non-POSIX systems. Is there another way to do this with maximum portability? 回答1: Perl comes

How can I check (peek) STDIN for piped data in Perl without using select?

拜拜、爱过 提交于 2019-12-03 12:04:43
I'm trying to handle the possibility that no arguments and no piped data is passed to a Perl script. I'm assuming that if there are no arguments then input is being piped via STDIN. However if the user provides no arguments and does not pipe anything to the script, it will try to get keyboard input. My objective is to provide an error message instead. Unfortunately, select() is not portable to some non-POSIX systems. Is there another way to do this with maximum portability? Perl comes with the -t file-test operator, which tells you if a particular filehandle is open to a TTY. So, you should be