Professional Web Applications Themes

Email Address Arguments - PERL Beginners

Hi Perl Mongers, I'm trying to p 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 com else.com or # ls -la | mailer or # mailer com ls.out so, I can check for no arguments with: if( ARGV ) { #process args here } and, I can match email addresses with this regex: /^.+.+/ I ...

  1. #1

    Default Email Address Arguments

    Hi Perl Mongers,

    I'm trying to p 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 com else.com

    or

    # ls -la | mailer

    or

    # mailer com ls.out

    so, I can check for no arguments with:
    if( ARGV ) {
    #process args here
    }

    and, I can match email addresses with this regex:
    /^.+.+/

    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:

    # ls -la | mailer com wrong.com com

    I know I'm just missing something simple.

    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?

    --Errin
    Errin Guest

  2. #2

    Default Re: Email Address Arguments

    > Hi Perl Mongers, 

    So in this case you have two arguments in ARGV and waiting text on
    STDIN? Is it this last part that is confusing you.
     

    Ok an easy one nothing in ARGV.
     

    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.
     

    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.
     

    What have you tried? Where did you fail? You know better than to post
    without code :-).
     
    com 

    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.
     

    Consider the AppConfig module too, it has some more capability that
    might come in handy this time.
     

    Don't give up, never admit defeat....

    http://danconia.org

    Wiggins Guest

  3. #3

    Default Re: Email Address Arguments

    On Tue, 12 Oct 2004 09:26:12 -0600, Wiggins d Anconia
    <org> wrote: [/ref]
    <<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.
    >[/ref]

    yes ... I'll explain below

    <<SNIP>> 
    >
    > 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.
    >[/ref]

    Yes ... I'm just not to the point where I'm making this pretty yet,
    need to p the arguments first and the above (dirty) regex works
    for this purpose.
     [/ref]
    <<SNIP>> 

    I know, I know. I just was having a brain-empty kinda morning. I
    couldn't kick-start the thinking!

    <<SNIP>> 

    The above is exactly what I needed to get me thinking! Thanks!!

    <<SNIP>> 

    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] =~ /^.+.+/ ) {
    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 foobar fredflinstone test.txt

    works fine, but:

    # ls -l | mailer foobar fredflinstone
    or
    # mailer foobar fredflinstone

    gives the following output:

    # mailer foobar fredflintstone
    There are arguments
    Use of uninitialized value in pattern match (m//) at ./mailtest4 line 15.
    foobar, fredflintstone,
    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
    Errin Guest

  4. #4

    Default Re: Email Address Arguments

    On Tue, 12 Oct 2004 09:26:12 -0600, Wiggins d Anconia wrote:

    <snip>

    Wiggins, why do you insist in starting a new thread everytime you reply to
    a posting? Although your posting are usually very pertinent, it's not good
    ng technique and it really clutters up my newsreader... Please keep all
    replies within a thread unless a new thread is warranted.
    Thanks.

    Chris.
    Chris Guest

  5. #5

    Default Re: Email Address Arguments

    I figured it out. I thought I'd post what I found.
     

    The above line of code was the culprit. I added a check to make
    sure ARGV wasn't empty and everything worked out. This line looks
    like this now:
    while( ARGV && $ARGV[0] =~ /^.+.+/ ) {
     

    --Errin
    Errin Guest

Similar Threads

  1. Invalid_Viewstate with email address
    By kmacintyre in forum ASP.NET Security
    Replies: 2
    Last Post: September 7th, 11:27 AM
  2. email address??
    By RichyMan in forum Macromedia Dynamic HTML
    Replies: 7
    Last Post: August 2nd, 04:29 PM
  3. Getting email address.
    By Sailor in forum Microsoft Access
    Replies: 0
    Last Post: August 3rd, 11:22 AM
  4. Sharing Email Address
    By Colin in forum Windows Networking
    Replies: 3
    Last Post: July 31st, 07:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139