walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
Now, suppose we need to take that and get output like this: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
I have always found a way to do it, using hash of hashes, like in the code below:sales:bob@foo.com,joe@foo.com,debbie@foo.com,john@foo.com retail:steve@bar.com,judy@bar.com support:david@blah.com,jose@blah.com
That is a horrible way to do it, and I know this. This has been one thing that has been very difficult for me in Perl, is wrapping my mind around the best way to map data like this.%hash; while (<>) { my ($dept,$email)=split(/:/); $hash{$dept}{'email'} = $email; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best Way to Map Data
by toolic (Bishop) on Jun 25, 2010 at 21:01 UTC | |
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 | |
|
Re: Best Way to Map Data
by jwkrahn (Abbot) on Jun 26, 2010 at 00:49 UTC | |
|
Re: Best Way to Map Data
by biohisham (Priest) on Jun 26, 2010 at 05:23 UTC |