Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by Kenosis (Priest)
on Nov 10, 2013 at 15:28 UTC ( #1061908=note: print w/replies, xml ) Need Help??


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

Deferencing the array reference that's the value associated with the hash key "NI" will get you there:

use strict; use warnings; use List::Util qw/min/; my %matrix = ( NI => [ 1, 1, 3, 4 ] ); my @NI_index = grep { $matrix{NI}->[$_] == min @{ $matrix{NI} } } 0 .. + $#{ $matrix{NI} }; print "@NI_index";

Output:

0 1

Hope this helps!

Replies are listed 'Best First'.
Re^2: Returning indices with same values for array within hash.
by LanX (Bishop) on Nov 10, 2013 at 15:55 UTC
    yes, but you don't really need the arrow after the first nesting level! =)

    DB<108> %matrix = (NI => [1 ,1 ,3 ,4] ); => ("NI", [1, 1, 3, 4]) DB<109> $matrix{NI}[3] => 4

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Good point!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061908]
help
Chatterbox?
[Happy-the-monk]: holli: Heizungszü ndungselektrik?
[holli]: Happy-the-monk: not quite
[holli]: I just ordered a pair of deans connectors to replace them. probably propriatary

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2017-11-19 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (281 votes). Check out past polls.

    Notices?