in reply to Best Way to Map Data
use strict; use warnings; my %hash; while (<DATA>) { chomp; my ($dept,$email)=split(/:/); push @{ $hash{$dept} }, $email; } for (sort keys %hash) { print "$_:", join(',', @{ $hash{$_} }), "\n"; } __DATA__ sales:bob@foo.com sales:joe@foo.com retail:steve@bar.com sales:debbie@foo.com sales:john@foo.com support:david@blah.com retail:judy@bar.com support:jose@blah.com
Prints:
retail:steve@bar.com,judy@bar.com sales:bob@foo.com,joe@foo.com,debbie@foo.com,john@foo.com support:david@blah.com,jose@blah.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best Way to Map Data
by walkingthecow (Friar) on Jun 25, 2010 at 21:18 UTC | |
by GrandFather (Saint) on Jun 25, 2010 at 22:58 UTC | |
by Anonymous Monk on Jun 26, 2010 at 04:52 UTC | |
by toolic (Bishop) on Jun 26, 2010 at 12:32 UTC |