in reply to How can one find five max values and five min values with positions in descending and ascending order from arrays?

Keeping it simple. If you really only need the output you gave

#!/usr/bin/perl use strict; use warnings; use 5.010; use Data::Dumper; use constant IWANT => 5; my @names = qw/c d e f k l m n o p q r s t u/; my @vals = qw/4 6 5 2 9 7 8 3 3 5 8 8 2 4 12/; my @data; my $pos = 1; for my $val (@vals) { # Build a table my $name = shift @names; my $rec = sprintf "%2d corresponds to %s at pos %2d", $val, $name +, $pos++; push @data, $rec; } say "\nSmall to Big"; @data = sort @data; for (0..IWANT-1) { say $data[$_]; } say "\nBig to Small"; for (1..IWANT) { say $data[-$_]; }

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!
  • Comment on Re: How can one find five max values and five min values with positions in descending and ascending order from arrays?
  • Download Code