> Hi Perl Mongers, > > I'm trying to parse some command line options. > > I'm expecting either no arguments, email addresses or email addresses > and file names/piped input. This script will take the email addresses > and send the contents of a file to them, or the output of a piped > command. So, I would expect something like this: > > # ls -la | mailer [EMAIL PROTECTED] [EMAIL PROTECTED] >
So in this case you have two arguments in @ARGV and waiting text on STDIN? Is it this last part that is confusing you. > or > > # ls -la | mailer > Ok an easy one nothing in @ARGV. > or > > # mailer [EMAIL PROTECTED] ls.out > Ok so in this case ls.out as you point out won't have an @ character, so we can assume that it is a file to read. So the question becomes, does this have to be the last argument, can there be multiple files, is it an error if an argument doesn't look like an email AND isn't a file? These are design issues, but all can be worked around depending on the answers. > so, I can check for no arguments with: > if( @ARGV ) { > #process args here > } > > and, I can match email addresses with this regex: > /[EMAIL PROTECTED]/ > Well you can start to match email addresses. It is better to match them with Email::Valid once you have what you think is an address. > I guess I'm asking for help on putting this stuff together. When I > get done, I'd like to see a single string with the email addresses in > it, separated by commas. I've been trying lots of stuff, but none of > it is working. I can't seem to strip off the email addresses from the > front of @ARGV without getting hung up when I get to the end, or if > there is an (incorrectly) placed argument in the middle of addresses > that is NOT an address, like this: > What have you tried? Where did you fail? You know better than to post without code :-). > # ls -la | mailer [EMAIL PROTECTED] wrong.com [EMAIL PROTECTED] > > I know I'm just missing something simple. > Again, what have you tried? So it goes something like, check for arguments, check that the arguments look like email addresses, if not then maybe it is a file, check to see if it exists (throw warning/error), if so then push it to a list and go to the next one. If it is a file you could push it to a different list. Then check STDIN for input, store it to an array for your message. Then check your list of files, import them into the content list (or even better maybe you want to attach them!!). If something is missing throw an error or set some defaults, if not send the message. Take it a chunk at a time, run it hundreds of times with lots of print statements until you have what you want. > I did think about using one of the getopt()/getopts() modules, but I'd > rather not have to use a command-line flag/option to make this all > work. Can you guys help me out? > Consider the AppConfig module too, it has some more capability that might come in handy this time. > --Errin > Don't give up, never admit defeat.... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>