On Fri, 22 Jun 2001, Aaron Lawson wrote:

>          I have a perl problem that seems like it should have a simple and
> easy solution but that I can't figure out.  I am trying to determine which
> of a set of scalars has the highest numeric value and then to get the NAME
> of the scalar (not the value) to use this to tell a user what kind of file
> they're dealing with.  Basically, the output of a long series of
> calculations that analyzes newswire ends up with 5 numeric values (these
> are scores for each domain): $financial, $sports, $foreigh_affairs,
> $politics, $human_interest.  These five scalars are floating point numbers,
> as I said, I'm just looking for some way of figuring out which has the
> highest value and returning the name of the variable.

Sure, just sort the values and put them into an array:

@sorted_values = sort { $a <=> $b } @unsorted;

$a and $b are automatically assigned -- don't declare them or you will get
errors.

-- Brett
                                   http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
But soft you, the fair Ophelia:
Ope not thy ponderous and marble jaws,
But get thee to a nunnery -- go!
                -- Mark "The Bard" Twain

Reply via email to