That doesn't look like code. But your problem intrigued me. The below code gets you the duplicates removed similar to what you're looking for, but you'll need to improve it a bit* to get the exact data format you're after.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data = [ { 'prod_order' => '702164', 'operation' => '10', 'machine' => 'W01', }, { 'prod_order' => '702164', 'operation' => '10', 'machine' => 'W02', }, { 'prod_order' => '702164', 'operation' => '10', 'machine' => 'W01', }, { 'prod_order' => '702164', 'operation' => '10', 'machine' => 'W02', }, { 'prod_order' => '702164', 'operation' => '10', 'machine' => 'W03', }, { 'prod_order' => '702164', 'operation' => '100', 'machine' => 'W03', } ]; my %hash = (); my @newdata = grep { ! $hash{ $_->{operation} . $_->{machine} }++ } @$ +data; print Dumper @newdata;

Output:

$VAR1 = { 'operation' => '10', 'prod_order' => '702164', 'machine' => 'W01' }; $VAR2 = { 'operation' => '10', 'prod_order' => '702164', 'machine' => 'W02' }; $VAR3 = { 'operation' => '10', 'prod_order' => '702164', 'machine' => 'W03' }; $VAR4 = { 'operation' => '100', 'prod_order' => '702164', 'machine' => 'W03' };

* FYI, since the OP didn't show us any effort, I figure if they really need the result as $data = [ { .. => .. }, { .. => .. } ]; they can add a couple of characters and change a few sigils in what I've posted.



--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

In reply to Re^3: Need help with removing duplicate hash keys from array of hashes by chargrill
in thread Need help with removing duplicate hash keys from array of hashes 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.