On Tue, 12 Oct 2004 09:26:12 -0600, Wiggins d Anconia
<[EMAIL PROTECTED]> wrote:
> > Hi Perl Mongers,
> >
> > I'm trying to parse some command line options.
> >
<<SNIP>>
> >
>
> So in this case you have two arguments in @ARGV and waiting text on
> STDIN? Is it this last part that is confusing you.
>
yes ... I'll explain below
<<SNIP>>
> >
> > 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.
>
Yes ... I'm just not to the point where I'm making this pretty yet,
need to parse the arguments first and the above (dirty) regex works
for this purpose.
> > I guess I'm asking for help on putting this stuff together. When I
<<SNIP>>
>
> What have you tried? Where did you fail? You know better than to post
> without code :-).
I know, I know. I just was having a brain-empty kinda morning. I
couldn't kick-start the thinking!
<<SNIP>>
>
> 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.
>
The above is exactly what I needed to get me thinking! Thanks!!
<<SNIP>>
>
> Consider the AppConfig module too, it has some more capability that
> might come in handy this time.
I'll look into this, thanks.
I've cobbled some code together to test stuff out with:
#!/usr/bin/perl
use warnings;
use strict;
my @addresses;
my @message;
if( @ARGV ) {
print "There are arguments\n";
while( $ARGV[0] =~ /[EMAIL PROTECTED]/ ) {
push @addresses, $ARGV[0].', ';
shift;
}
print "@addresses\n";
} else {
print "There are no arguments\n";
}
while( <> ) {
if( /^.$/ ) {
last;
} else {
push @message, $_;
}
}
print "\n\nThe following message will be sent:\n";
print "@message\n";
I keep getting a warning when the file name's not on the command line.
In other words, If I use standard input for manual input, or if I
pipe the input to the mailer script.
# mailer [EMAIL PROTECTED] [EMAIL PROTECTED] test.txt
works fine, but:
# ls -l | mailer [EMAIL PROTECTED] [EMAIL PROTECTED]
or
# mailer [EMAIL PROTECTED] [EMAIL PROTECTED]
gives the following output:
# mailer [EMAIL PROTECTED] [EMAIL PROTECTED]
There are arguments
Use of uninitialized value in pattern match (m//) at ./mailtest4 line 15.
[EMAIL PROTECTED], [EMAIL PROTECTED],
This is a test message.
.
The following message will be sent:
This is a test message.
I know that the "Use of unintialized value ..." message has to do with
the fact that input is sitting on STDIN (or, will be), but I can't
figure out how to deal with it.
Thanks for any help
--Errin
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>