in reply to How can I get the four highest valued letters in an array?
You could use zip from List::MoreUtils to mesh the arrays into a hash, then sort the keys by the values:
Output:use strict; use warnings; use feature 'say'; use Data::Dumper; use List::MoreUtils 'zip'; my @x = qw/d b c e a f/; my @y = qw/4 6 5 2 9 1/; my %h = zip @x, @y; my @z = ( sort { $h{ $b } <=> $h{ $a } } keys %h )[0..3]; say Dumper \@z; __END__
$VAR1 = [ 'a', 'b', 'c', 'd' ];
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I get the four highest valued letters in an array?
by supriyoch_2008 (Monk) on Jun 01, 2017 at 14:45 UTC |