At 05:35 PM 5/30/02 -0700, drieux wrote:
>volks,
>
>it's crisis time in uncle drieux's neighborhood, so that
>I could simplify the code maintenance I opted to use a variable
>inside another loop that is based upon the Max index value of
>the keys in %decrHash - all of which are ints....
And apparently >= 0 based on the code below too. Do these ints greatly
exceed the number of keys in the hash? Might use an array otherwise,
assuming you have no undef values.
> #
> # what we use so we do not have to change the code below
> #
> my $decrCount=0;
> #
> # one way to implement 'get Max Index'
> #
> for ( keys %decrHash ) { $decrCount = $_ if ( $_ > $decrCount) ;}
>
>the other one liner would look like:
>
> my ($decrCount) = sort { $b <=> $a } keys %decrHash;
>
>I really wanted to do that with a 'shift' on the list returned
>by sort - but it whined at me
Because shift is prototyped to require an argument that starts with '@'.
>and I told it to go away and just
>opted to list context the $decrCount, and throw away the rest
>of the data.....
List slice:
my ($decrCount) = (sort { $b <=> $a } keys %decrHash)[0];
Not that it makes any difference in this case...
>now I want to do which one of these for what reason again????
Seems like your application should be keeping track of the max value for
other reasons...
--
Peter Scott
Pacific Systems Design Technologies Boston Perl Classes in July:
http://www.perldebugged.com/ http://stemsystems.com/class/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]