Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^4: Get just the unique value

by Anonymous Monk
on Apr 05, 2013 at 17:45 UTC ( #1027181=note: print w/replies, xml ) Need Help??

in reply to Re^3: Get just the unique value
in thread Get just the unique value

OK, let me try again, I have a data structure like this:
my $data = [ { 'type' => 'Paper' }, { 'type' => 'Paper' }, { 'type' => 'Plastic' }, { 'type' => 'Plastic' }, { 'type' => 'Plastic' }, { 'type' => 'Plastic' }, { 'type' => 'Cotton' }, { 'type' => 'Cotton' }, { 'type' => 'Cotton' }, { 'type' => 'Cotton' }, { 'type' => 'Cotton' }, { 'type' => 'Paper' }, { 'type' => 'Paper' }, { 'type' => 'Paper' }, { 'type' => 'Paper' }, { 'type' => 'Paper' }, ];
I need to process this array and filter out the duplicated ones:
my $res; for my $entry (@$data) { #$entry->{type} = [] unless exists $entry->{type}; push @$res, $res{$entry->{type}}; } print Dumper @$res;
I just cant get it to work.

Replies are listed 'Best First'.
Re^5: Get just the unique value
by CountOrlok (Friar) on Apr 05, 2013 at 18:18 UTC
    Use the code hdb posted

      Yes, I think it should work.

Re^5: Get just the unique value
by hdb (Monsignor) on Apr 05, 2013 at 18:22 UTC

    I think if you feed your new structure to some of the proposals it will work...

      I tested, none of them work unfortunately, I will look also where.
        Maybe if you gave us the desired output...

        How about this?

        my %types; my $res; foreach my $entry (@$data) { push @$res, $entry unless $types{$entry->{"type"}}++; } print Dumper $res;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027181]
[Corion]: Also see Config::V, which is less of that hackery, or that hackery hidden in a module ;)
[1nickt]: The problem was with Perlbrew
[Corion]: Whoops - Config::Perl::V
[1nickt]: I found that when using Perlbrew as recommended, with cpanminus in the system perl lib, such tests were failing to detect the data about the perl that was the install destination.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-10-18 15:39 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (249 votes). Check out past polls.