jkelly has asked for the wisdom of the Perl Monks concerning the following question:
Another STDIN-related question. (I think. :/)
I'm refactoring an app that analyses email messages. I'd like to set up a conditional at the beginning of the script where I can take piped in data if it's available, and do something else if it's not (in this case, go look in an IMAP folder.) In other words, I'd like to be able to call...
./script.pl
...and have my script do its default behavior (use IMAP), or pipe it a message directly...
cat sample.eml | ./script.pl
or
./script.pl < sample.eml
and just deal with sample.eml.
Of course, when I execute, my script sits there and waits for STDIN. One of those moments where my stupidity becomes painfully obvious to me only after the fact. But I don't know which way to go with this, and I don't know how to search for the answer.if ( <STDIN> ) { print "Got STDIN.\n"; # Look for more STDIN till there's no more. } else { print "Default behavior.\n"; # Go connect to the IMAP server and feed there. }
All I know is that I want this program to take what gets offered it, and if nothing is offered, to go do its own thing without sitting around and waiting for a handout.
Any /(help|nudges in the right direction)/ will be much appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Piping input as an option
by dave_the_m (Monsignor) on Jul 04, 2007 at 11:12 UTC | |
by jkelly (Initiate) on Jul 04, 2007 at 13:04 UTC | |
|
Re: Piping input as an option
by Joost (Canon) on Jul 04, 2007 at 11:14 UTC | |
|
Re: Piping input as an option
by whereiskurt (Friar) on Jul 04, 2007 at 13:21 UTC | |
by jkelly (Initiate) on Jul 05, 2007 at 15:38 UTC | |
by whereiskurt (Friar) on Jul 05, 2007 at 20:50 UTC | |
|
Re: Piping input as an option
by citromatik (Curate) on Jul 04, 2007 at 11:40 UTC | |
by jkelly (Initiate) on Jul 05, 2007 at 14:59 UTC |