Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Returning indices with same values for array within hash.

by Athanasius (Abbot)
on Nov 10, 2013 at 15:58 UTC ( #1061911=note: print w/ replies, xml ) Need Help??


in reply to Returning indices with same values for array within hash.

Or is there another way to do it?

More of a variation on a theme (which builds on the previous answers):

use strict; use warnings; use List::Util qw( min ); use List::MoreUtils qw( indexes ); my %matrix = ( NI => [1, 5, 1, 3, 4] ); my $minimum = min @{ $matrix{NI} }; my @indices = indexes { $_ == $minimum } @{ $matrix{NI} }; print "@indices";

Output:

1:57 >perl 774_SoPW.pl 0 2 1:57 >

See List::MoreUtils.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Returning indices with same values for array within hash.
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2015-07-07 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls