@kyanny's blog

My thoughts, my life. Views/opinions are my own.

標準入力 STDIN にインプット・リダイレクションまたはパイプで何か渡されているかどうかを調べるには

if (-t STDIN) {
    print 'opened';
}
else {
    print 'piped or input redirection';
}

こんなんでいいのかな。 perldoc -f -t とかでみると ‐t Filehandle is opened to a tty. と書いてあって、何のことやらよくわからない。

#!perl
# $Id$
use strict;
use warnings;

if (-t STDIN) {
    print 'opened';
}
else {
    print 'piped or input redirection';
}

1;

試してみてそうなるからそういうもんなんだろうけど、なんかむねがつかえたままのような嫌な感じ。