in reply to Top and bottom 10 percent elements of an array
How about a solution with map.
@array = (2 ,4, 3, 8, 9, 12, 13, 20, 18, 7 ); my $c=0; @sort_a_pos = sort {$a->[1]<=>$b->[1]} map { [$c++ => $_] } @array; $pct = @array / 10; $_->[1] = "B" for @sort_a_pos[0 .. $pct]; $_->[1] = "-" for @sort_a_pos[$pct+1 .. $#array-$pct-1]; $_->[1] = "A" for @sort_a_pos[$#array-$pct .. $#array]; @finalarray = map {$_->[1] } sort { $a->[0] <=> $b->[0] } @sort_a_pos +; print "@finalarray";
print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Top and bottom 10 percent elements of an array
by ikegami (Patriarch) on Apr 29, 2010 at 18:38 UTC |
In Section
Seekers of Perl Wisdom