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>) {
        process the text from STDIN here;
} else {
        print usage statement;
}

I tend to use:


    if (@ARGV == 0 and -t) {
        die "Usage: $0 INPUT\n";
    }

    while (<>) {
        ## process input file(s) here
    }

This will process any number of files on the command-line, or
read from STDIN -- but if STDIN is the terminal it won't wait for
the user to start typing.

--
Steve

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to