my %hash =( 'script' => 'foo.pm', 'params' => { 'err' => '99', 'FILE' => 'fileA' }, 'par_global' => { 'err' => '99', 'err' => '20', 'FILE_READ' => 'fileB', }, 'testset' => ['test1'] );

I am extracting key value pairs from %hash, but in case if key=values are similar, it should pick only one entry of it rather than picking both the entries.

Output from my code FILE=fileA err=99 script:foo.pm foo.pm FILE_READ=fileB err=99 err=20 testset:test1

Output required FILE=fileA err=99 script:foo.pm foo.pm FILE_READ=fileB err=20 testset:test1

Should list only one entry of err=99 rather than two entries

Code used

foreach my $key (keys %hash) { if ( ref $hash{$key} ne 'HASH' && ref $hash{$key} ne 'ARRAY' ) { print"$key:$hash{$key}\n"; if( (defined $key) && ($key eq 'script') ) { print"$hash{$key}\n"; } } if( ref $hash{$key} eq 'HASH' ) { foreach my $k (keys %{$hash{$key}}) { print"$k=$hash{$key}{$k}\n"; } } elsif( ref $hash{$key} eq 'ARRAY' ) { print"$key:$hash{$key}[0]\n"; } }

In reply to Remove similar key=value pair from HOH by vaibhav07

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.