[EMAIL PROTECTED] wrote:
I am looking to send a mail message to a large group of users and
indicate which groups they are assigned to. Currently I have a tab
deliniated file which has in column 1 the email address, column 2 the
group, and column 3 the user's name. Using sample data I would like:

[EMAIL PROTECTED] T. Dog
[EMAIL PROTECTED] Doe
[EMAIL PROTECTED] T. Dog
[EMAIL PROTECTED] Doe
[EMAIL PROTECTED] Doe
[EMAIL PROTECTED] T. Dog
[EMAIL PROTECTED] Doe
[EMAIL PROTECTED] Doe

To be formatted like:

[EMAIL PROTECTED], Football, Hockey\tSpot T. Dog
[EMAIL PROTECTED], Football\tJonathon Doe
[EMAIL PROTECTED], Hockey\tJane Doe
[EMAIL PROTECTED] Doe

...so that I do not have to send multiple emails. I am not sure if I
should be using a hash or an array to accomplish this task. I would
like to know how to loop through the data to pull out the groups for
each email address. It would also be nice if I could sort each group
since some users have over 30+ groups assigned to them.

Any assistance would be greatly appreciated,

Probably something like this:

#!/usr/bin/perl
use warnings;
use strict;

my $old_file = 'tab_deliniated_file';
my $new_file = 'tab_deliniated_new';

open my $OLD, '<', $old_file or die "Cannot open '$old_file' $!";
open my $NEW, '>', $new_file or die "Cannot open '$new_file' $!";

my %data;
while ( <$OLD> ) {
    my ( $email, $group, $name ) = split /\t/;
    push @{ $data{ $email, $name } }, $group;
    }

for my $key ( keys %data ) {
    local $" = ', ';
    $key =~ s/$;/[EMAIL PROTECTED]/;
    print $NEW $key;
    }

__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/


Reply via email to