Hi there Monks!
I am trying to check if this particular value already is in this array to avoid having duplicated values in it.
I just can't get this code to work.
I have this code sample that I hope shows what and where I am having issues.

This is the first array:
… my @loop_names = (); foreach my $row (@{$names_data}) { my %row_data; $row_data{NAMES} = $row->{NAMES} || ''; push(@loop_names, \%row_data); } # Dumper of @loop_names; =code $VAR1 = { 'NAMES' => 'John Doe' }; $VAR2 = { 'NAMES' => 'Mary Lou' } =cut

This is from the second array:
my @loop_addr = (); foreach my $row (@{$all_party_id_data}) { my %row_data; $row_data{FULL_NAME} = $row->{FULL_NAME} || ''; $row_data{ADDR} = $row->{ADDR} || ''; $row_data{ZIP} = $row->{ZIP} || ''; warn Dumper $row_data{FULL_NAME}; # it will get "Mary Lou" # I just want @loop_names to have what is unique @loop_names = map /$row_data{FULL_NAME}/ ? () : $_, @loop_names; $row_data{N_DATA} = \@loop_names; push(@loop_addr, \%row_data); } # Dumper of @loop_addr =code $VAR1 = { 'FULL_NAME' => 'Mary Lou', 'ADDR' => '100 - Main Street', 'ZIP' => '12345', 'EMAIL_DATA' => [ { 'NAMES' => 'John Doe' }, { 'NAMES' => 'Mary Lou' # this shouldn't be here + } ], }; =cut


I would like this array to only have this at the end, because “John Doe” is the only unique value:
$VAR1 = { 'FULL_NAME' => 'Mary Lou', 'ADDR' => '100 - Main Street', 'ZIP' => '12345', 'EMAIL_DATA' => [ { 'NAMES' => 'John Doe' }, ], };

Thanks for looking!

In reply to Get only unique values into array 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.