Hi,

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!

use 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; }
Output
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
You might want to check the following documentation for more info: Also check this module: Data::Dumper
it stringified perl data structures, suitable for both printing and eval!!!


In reply to Re: Returning values from a sub routine. by 2teez
in thread Returning values from a sub routine. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.