in reply to Returning a hash instead of two arrays help!
There are lots of ways this could go and a best answer depends a lot on the bigger picture. In the context of the narrow picture shown using a hash slice or two is the easy way to populate a hash:
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); my @email = qw(joe@test.com mary@test.com ann@nowhere.com pete@here.com amy@ok.com jerry@b.com); my %emails; @emails{@names_all} = @email_all; @emails{@names} = @email; return \%emails; }
Prints:
Joe: joe@test.com amy: amy@ok.com ann: ann@nowhere.com jerry: jerry@b.com mary: mary@test.com pete: pete@here.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Returning a hash instead of two arrays help!
by Anonymous Monk on Jul 31, 2012 at 13:33 UTC | |
by GrandFather (Saint) on Jul 31, 2012 at 22:55 UTC |