Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want a script that reads both from stdin and from a any file parameter. In other words a script that can be used as any other unix command line tool.
The problem is that if there's no stdin and no command line args then the script just waits for input.
I want to test to see if there is any input from a pipe or file and if not close with a usage message. How can I test, <>?
Thanks
use strict; use warnings; while (<>) { print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing <>
by Corion (Patriarch) on Oct 03, 2011 at 15:31 UTC | |
by Anonymous Monk on Oct 03, 2011 at 15:49 UTC | |
|
Re: Testing <>
by ikegami (Patriarch) on Oct 03, 2011 at 15:44 UTC | |
by Anonymous Monk on Oct 04, 2011 at 08:31 UTC | |
by Corion (Patriarch) on Oct 04, 2011 at 08:35 UTC | |
by Anonymous Monk on Oct 04, 2011 at 09:01 UTC | |
|
Re: Testing <>
by kennethk (Abbot) on Oct 03, 2011 at 15:25 UTC | |
by Anonymous Monk on Oct 03, 2011 at 15:35 UTC | |
|
Re: Testing <>
by Anonymous Monk on Oct 03, 2011 at 15:32 UTC |