On 1/29/07, John W. Krahn <[EMAIL PROTECTED]> wrote:
Kenton Brede wrote:
> I need some advice as to how to approach this problem.
>
> I've got a mail alias file, space delimited and sorted on the second
> column like:
>
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> [EMAIL PROTECTED] [EMAIL PROTECTED]
>
> I need to send an email to each of the addresses on the right.  I
> could send this line by line but then jsmith would get two emails,
> when I want to send one.  The second thing I need to do is grab all
> these addresses to use as variables in the body of the email that will
> get sent.
>
> The email would read something like:
> 
----------------------------------------------------------------------------------------------------------------------
>
> These are your email aliases: [EMAIL PROTECTED],  [EMAIL PROTECTED]
> This is your official email address: [EMAIL PROTECTED]
> 
----------------------------------------------------------------------------------------------------------------------
>
>
> The part I need help with is how to grab lines in the file with the
> same email address (address on the right) and treat them as "one
> record" as well as treat those with a single email address as one
> record?
>
> Maybe another way to state this is how do I get the lines with
> [EMAIL PROTECTED] into an array, process that, and then grab a
> line with a single address like [EMAIL PROTECTED] and process
> that?
>
> Thanks for any pointers.  I'd include some code but I don't even know
> where to start.

Something like this should work (UNTESTED):

my $mail_alias_file = 'mail alias file';

open my $fh, '<', $mail_alias_file or die "Cannot open '$mail_alias_file' $!";

my %emails;
while ( <$fh> ) {
    my ( $alias, $email ) = split or next;
    push @{ $emails{ $email } }, $alias;
    }

for my $email ( keys %emails ) {
    local $" = ', ';
    print <<TEXT;
These are your email aliases: @{$emails{$email}}
This is your official email address: $email
TEXT
    }

__END__

This is getting very close to what I'm trying to do, see below.  There
is just one point I'm stuck on, how to grab the username portion of
the email address into a variable.  I'm able to get the username of
the official email address @mail.nowhere.com, but I can't seem to
figure out how to grab each username of the aliases @nowhere.com.
What I've written below seems to grab a "slice" or something and isn't
a true array value.  What I would like is to grab j_johnson and
jim_johnson from [EMAIL PROTECTED] and [EMAIL PROTECTED]
So I could use each username as a variable for a different portion of
the email.

Thanks everyone for your help.
Kent

----------------------------------------------------------------------------------------------------
my $mail_alias_file = 'addresses';

open my $fh, '<', $mail_alias_file or die "Cannot open '$mail_alias_file' $!";
my %emails;
my @id;
while ( <$fh> ) {
  my ( $alias, $email ) = split or next;
  push @{ $emails{ $email } }, $alias;
}

for my $email ( keys %emails ) {
   @names = @{$emails{$email}};

   print "These are your mismatched email names: ";

   for my $line ( @names ) {
       my @n = ($line =~ /(.*)@/);
       my @netid = split(/@/, $email);
       print "$n[0],  $netid[0]";
   }

local $" = ', ';
my $message = <<TEXT;

These are your email aliases: @{$emails{$email}}
This is your official email address: $email

TEXT

print $message;
}
------------------------------------------------------------------------------------------------------------

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


Reply via email to