raptor,

Note that I changed your outer %struct squigglies to parens. I've left some debug prints in the following code for illustrative purposes:

#!/usr/local/bin/perl use strict; my %struct = ( row1 => { key0 => 'val0', key1 => 'val2', keyX => 'valX' }, row2 => { key0 => 'val0', key1 => 'val1', keyX => 'valX' }, row3 => { key0 => 'val0', key1 => 'val1', keyX => 'valY' }, row9 => { key0 => 'val0', key1 => 'val1', keyX => 'valY' }, rowX => { key0 => 'val0', key1 => 'val1', keyX => 'valX' } ); my %ndxhash = (); print "Before deletions:\n"; foreach my $row (keys(%struct)) { print "\$row: $row"; print " key0: $struct{$row}{key0} "; print " key1: $struct{$row}{key1} "; print " keyX: $struct{$row}{keyX} \n"; ## build a key to determine a uniqueness in %ndxhash my $ndxkey = Trim($struct{$row}{key0}) . Trim($struct{$row}{key1}) . Trim($struct{$row}{keyX}); if (exists $ndxhash{$ndxkey}) { ## this one is a duplicate delete $struct{$row}; } else { ## this is a unique one, add it to the %ndxhash $ndxhash{$ndxkey} = 1; } } print "\n\nAfter deletions\n\n"; foreach my $row (keys(%struct)) { print "\$row: $row"; print " key0: $struct{$row}{key0} "; print " key1: $struct{$row}{key1} "; print " keyX: $struct{$row}{keyX} \n"; } sub Trim { my $InVar = shift; for ($InVar) { s/^\s+//; s/\s+$//; } if (! $InVar) { $InVar = " "; } return $InVar; }
Execution Results
Before Deletions: $row: rowX key0: val0 key1: val1 keyX: valX $row: row9 key0: val0 key1: val1 keyX: valY $row: row1 key0: val0 key1: val2 keyX: valX $row: row2 key0: val0 key1: val1 keyX: valX $row: row3 key0: val0 key1: val1 keyX: valY After Deletions $row: rowX key0: val0 key1: val1 keyX: valX $row: row9 key0: val0 key1: val1 keyX: valY $row: row1 key0: val0 key1: val2 keyX: valX
Hope this is clear enough.

Update: removed unused variable in Trim sub


In reply to Re: removing the repeated info... by jlongino
in thread removing the repeated info... by raptor

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.