[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Closest hash value



> You don't need %temp; just sort directly.
> 
> $val = (sort {abs($a - $key) <=> abs($b - $key)} keys %h)[0];
> 
> Of course, you could use an Orcish Maneuver or a Schwartzian Transform for
> the sort if you wanted.
> 
> Ronald

Ah, I see, thanks. I knew there was a one-liner here. I just couldn't quite
make it fit...

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe