in reply to Finding target unspecified value
If I understand your question correctly, you wish to find the largest element in an array. This is a fairly common task and the direct approach usually looks something like this:
use strict; use warnings; # you can initialize this any way you wish, this is proof of concept. my @source = ( 5, 53, 24, 38 ); my $maxseen = 0; my $seen_at = 0; my $cntr = 0; for ( @source ) { if ( $_ > $maxseen ) { $maxseen = $_; $seen_at = $cntr; } ++$cntr; }
No doubt, this is crude and someone will put up a one-liner using map or grep.
Update: changed it to have both the max element value and the position at which the max element value was first seen.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding target unspecified value
by AnomalousMonk (Archbishop) on Oct 21, 2013 at 03:22 UTC | |
by boftx (Deacon) on Oct 21, 2013 at 03:42 UTC | |
|
Re^2: Finding target unspecified value
by Anonymous Monk on Oct 20, 2013 at 20:13 UTC | |
by boftx (Deacon) on Oct 20, 2013 at 20:32 UTC |