Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: Get just the unique value

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

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

It still doesnt work, I am still getting duplicated "type":
$VAR1 = [ { 'reference' => '100 ', 'name' => 'Discount', 'type' => 'Paper' }, { 'reference' => '30 ', 'name' => 'Slice', 'type' => 'Cotton' }, { 'reference' => '340 ', 'name' => 'Money', 'type' => 'Plastic' }, { 'reference' => '100 ', 'name' => 'Documents', 'type' => 'Paper' }, { 'reference' => '45 ', 'name' => 'Part', 'type' => 'Cotton' }, { 'reference' => '40 ', 'name' => 'State', 'type' => 'Cotton' } ];

Replies are listed 'Best First'.
Re^3: Get just the unique value
by hdb (Prior) on Apr 05, 2013 at 17:28 UTC

    Well, these are the distinct records from your original array of hashes. You did not specify which value is to be unique. I would think that you should now be able from the answers here and the answers from your post yesterday: Accessing this array ref. to conclude whatever you wanted to achieve.

      I saw that posting here, just got the sample data from it to show my issue, but its not the same problem.
Re^3: Get just the unique value
by CountOrlok (Friar) on Apr 05, 2013 at 17:28 UTC
    It isn't clear what you want for output. You want to remove entries in the original data where type is duplicated, it seems, but how do you want to handle the case where reference or name is different? Which entry in the arrayref do you want to choose?
      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.
        Use the code hdb posted

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027174]
[LanX]: I told you the story about the “new" currency trading system of Dresdner Bank
[LanX]: ?
[Corion]: No, or I don't remember the story ;)
LanX my favourite don't tell me the proof of concept is good enough for production anecdote
[ambrus]: ah, it's one of thos
[Eily]: what, there's a difference between proof of concept and production?
[LanX]: 20 years ago traders were complaining about the latency of the trading system...
[ambrus]: I'm currently in the process of rewriting my proof of concept programs. They sort of developped organically as I was experimenting, so now I've got an ugly mess of multiple programs and one-liners held together by nothing. I'll have to rewrite them to som
[ambrus]: ething that's both cleanly organized and mostly automated.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-03-29 11:45 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.