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__
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/