On Mon, 29 Mar 2004 00:38:50 -0700
Bryan Harris <[EMAIL PROTECTED]> wrote:
> > Alternatively, you can use the '-t' operator:
> >
> > exit 0 if -t STDIN
>
>
> I've been waiting for this for a LONG time, thanks Smoot.
No problem. It took me a while to find the correct operator as well.
Please keep in mind that doing this breaks the de facto Unix standard
for filters. A simply command which is a filter (e.g takes
input from STDIN and sends output to STDOUT) is written without any
consideration whether the input is a terminal, pipe, socket or
otherwise. This makes it very simple to use the command in a pipeline or
standalone from the terminal.
There are cases where you may want to break this rule, but they are
rare. Also given the common Unix paradigm of a command taking its
arguments (not flags) as input files, I typically write my simple Perl
tools with the following paradigm:
process any flags here
while (<>) {
do something with the input
}
The magical <> operator is very handy.
--
Smoot Carl-Mitchell
Systems/Network Architect
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>