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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |