Timothy Donahue wrote: > I have a program that I am writing that I need to accept input from > either STDIN (for file redirections or pipes) or from the > command-line. The program manipulates email addresses for our mail > servers, so I should have the option to do either 'email_add > [EMAIL PROTECTED]' or 'email_add < /path/to/file'. > > I thought that an algorithm similar to this should work. > > if (defined(@ARGV) { > process the text from the command line here; > } elsif (@EmailList = <STDIN>) {
Obviously you're going to block here, so the usage doesn't get printed. > process the text from STDIN here; > } else { > print usage statement; > } > > When I run the program without any input it sits at the command line > until I either kill it, or I pass it some input from STDIN (typing a > ^D (control + D) will make it continue its execution). Is there any > way that I can test if there is information queued up in STDIN without > actually requiring that there be information there (or specifically I > believe that the test is looking for an EOF)? You can do something like this: if (@ARGV) { ... process from @ARGV } elsif (! -t) { # stdin not a tty ... process from stdin } else { ... print usage } This will print the usage if there are no arguments and stdin is not being redirected from a file or pipe. For documentation on -t, see 'perldoc -f -t' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>