On Fri, Jun 22, 2001 at 09:14:19AM -0400, Aaron Lawson wrote:
> Hi,
>          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.
> 
> Any ideas?  Thanks in advance.

Consider putting the data in a hash.  (Possibly it should have been
there to start with.)

my $top = (sort { $hash{$a} <=> $hash{$b} } keys %hash)[0];

Or something like that.

It's not terribly efficient if you have lots of values, but it's simple
and with 5 values you won't notice it.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to