in reply to Re: Returning a hash instead of two arrays help!
in thread Returning a hash instead of two arrays help!

Hi, I hope someone will get to this still, I have a similar problem and my question is, what if some of these elements are repeated what would be the best way to return these values?
use strict; use warnings; my $info = test(); for my $name (sort keys %$info) { printf "%-10s %s\n", "$name:", $info->{$name}; } sub test { my (@names_all, @email_all); my @names = qw(Joe mary ann pete amy jerry Joe ann); my @email = qw(joe@test.com mary@test.com ann@nowhere.com pete@here.com amy@ok.com jerry@b.com joe@test.com ann@nowhere. +com); my %emails; @emails{@names_all} = @email_all; @emails{@names} = @email; return \%emails; }

Thanks!

Replies are listed 'Best First'.
Re^3: Returning a hash instead of two arrays help!
by GrandFather (Saint) on Jul 31, 2012 at 22:55 UTC

    It depends on why you have "repeated elements". If you have multiple people with the same name then you probably need to use an ID code as the hash key instead of the name. If you have multiple email addresses per person then the value becomes an array instead of a single value and you can thus track all the addresses.

    True laziness is hard work