Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi there Monks!
I need to get only the unique value from this anonymous array of hashes, but I just don’t understand why this code can't?
I need to get only the unique value from this anonymous array of hashes, but I just don’t understand why this code can't?
Thanks for looking!#/usr/bin/perl use strict; use Data::Dumper; my $data = [ { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Documents', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Money', 'reference' => '340 ', 'type' => 'Plastic' }, { 'name' => 'Money', 'reference' => '340 ', 'type' => 'Plastic' }, { 'name' => 'Money', 'reference' => '340 ', 'type' => 'Plastic' }, { 'name' => 'Money', 'reference' => '340 ', 'type' => 'Plastic' }, { 'name' => 'State', 'reference' => '40 ', 'type' => 'Cotton' }, { 'name' => 'State', 'reference' => '40 ', 'type' => 'Cotton' }, { 'name' => 'State', 'reference' => '40 ', 'type' => 'Cotton' }, { 'name' => 'Slice', 'reference' => '30 ', 'type' => 'Cotton' }, { 'name' => 'Part', 'reference' => '45 ', 'type' => 'Cotton' }, { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, ]; my $res; for my $entry (@$data) { #$entry->{type} = [] unless exists $entry->{type}; push @$res, $entry->{type} unless $entry; } print Dumper @$res;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Get just the unique value
by CountOrlok (Friar) on Apr 05, 2013 at 15:49 UTC | |
Re: Get just the unique value
by hdb (Monsignor) on Apr 05, 2013 at 16:02 UTC | |
by Anonymous Monk on Apr 05, 2013 at 17:16 UTC | |
by hdb (Monsignor) on Apr 05, 2013 at 17:28 UTC | |
by Anonymous Monk on Apr 05, 2013 at 18:09 UTC | |
by CountOrlok (Friar) on Apr 05, 2013 at 17:28 UTC | |
by Anonymous Monk on Apr 05, 2013 at 17:45 UTC | |
by CountOrlok (Friar) on Apr 05, 2013 at 18:18 UTC | |
| |
by hdb (Monsignor) on Apr 05, 2013 at 18:22 UTC | |
| |
Re: Get just the unique value
by jaredor (Priest) on Apr 05, 2013 at 18:26 UTC | |
Re: Get just the unique value
by NetWallah (Canon) on Apr 05, 2013 at 17:06 UTC |
Back to
Seekers of Perl Wisdom