in reply to Returning values from a sub routine.
Please, try the code below it's an addition to suaveant previous code.
It should do what you want or you can improve on it, until you get what you really want!
Outputuse strict; use warnings; my $info = test(); printing($info); sub printing { my ($args) = @_; foreach my $name ( keys %{$args} ) { # tell the number of emails attached to a person my $count = scalar @{ $args->{$name} }; # if more than one email is attached to a person # that individual is not Unique $count == 1 ? print "Unique: ", $name, " email: ", @{ $args->{$name} }, +$/ : print "Dups: ", $name, map { " email: $_$/" } @{ $args->{ +$name} }; } } sub test { my @names = qw(Joe mary ann pete amy jerry Joe ann John John ); 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.co +m John@test.com John@ok.com); my %emails; foreach my $name (@names) { push @{ $emails{$name} }, shift @email; } return \%emails; }
You might want to check the following documentation for more info:Unique: jerry email: jerry@b.com Unique: pete email: pete@here.com Dups: Joe email: joe@test.com email: joe@test.com Dups: John email: John@test.com email: John@ok.com Unique: amy email: amy@ok.com Dups: ann email: ann@nowhere.com email: ann@nowhere.com Unique: mary email: mary@test.com
|
|---|