in reply to Returning a hash instead of two arrays help!
use warnings; use strict; sub test { my %email_of; my @name = qw(Joe mary ann pete amy jerry); my @email = qw(joe@test.com mary@test.com ann@nowhere.com pete@her +e.com amy@ok.com jerry@b.com); for my $i (0 .. $#name) { $email_of{$name[$i]} = $email[$i]; } return \%email_of; } my $info = test(); foreach my $all (%$info) { print "$all\n"; }
Even fancier (see perldata):
sub test { my @name = qw(Joe mary ann pete amy jerry); my @email = qw(joe@test.com mary@test.com ann@nowhere.com pete@her +e.com amy@ok.com jerry@b.com); my %email_of; @email_of{@name} = @email; return \%email_of; }
|
|---|