On Fri, 2008-09-26 at 10:03 -0700, [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,
> 
> 

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;
$Data::Dumper::Maxdepth = 0;

my @names = ();
my %list = ();

while( <> ){
  chomp;
  my ( $email, $group, $name ) = split /\t/, $_;
  push @names, $name unless exists $list{$name};
  $list{$name}{email} = $email;
  $list{$name}{groups}{$group} = 1;
}
# print '%list : ', Dumper \%list;

for my $name ( @names ){
  my $groups = join( ', ', sort keys %{ $list{$name}{groups} } );
  print join( "\t", $list{$name}{email}, $groups, $name ), "\n";
}

__END__


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Linux is obsolete.
-- Andrew Tanenbaum


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


Reply via email to