Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: extracting only those keys with uniq values in array list

by BillKSmith (Monsignor)
on Apr 20, 2021 at 13:45 UTC ( [id://11131511]=note: print w/replies, xml ) Need Help??


in reply to extracting only those keys with uniq values in array list

Every reply you have received so far has a different interpretation of your requirements. If you are lucky, someone will correctly guess what you intend and post a solution. However, I recommend that you restate the problem in a way that we can all understand without guessing. Note that the word 'unique' can be ambiguous. It can mean 'values that only occur once' or 'the first occurrence of each value'. The function uniq of List::Util which you reference assumes the latter.
Bill
  • Comment on Re: extracting only those keys with uniq values in array list

Replies are listed 'Best First'.
Re^2: extracting only those keys with uniq values in array list
by v15 (Sexton) on Apr 20, 2021 at 14:08 UTC
    I agree with you. I edited the question so hopefully it makes more sense. Thanks
      Thanks for the clarification. Build the hash exactly as you show. Process the keys with grep
      use strict; use warnings; my %r_name = ( a => [ 1, 2 ], b => [ 3, 3 ], c => [ 1, 6 ], ); my @result = grep {$r_name{$_}[0] eq $r_name{$_}[1]} keys %r_name; print @result, "\n";

      Result

      b

      Note for next time: It is considered impolite to edit your post in a way that invalidates existing replies. Leave the existing text. Add a clearly marked UPDATE section.

      Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-18 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found