Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Why am I getting message «Operation "<=>": no method found,» ?

by Athanasius (Bishop)
on Aug 01, 2015 at 15:26 UTC ( #1137122=note: print w/replies, xml ) Need Help??


in reply to Why am I getting message «Operation "<=>": no method found,» ?

Hello RCH,

As 1nickt says, when $demo has the value 'problem', each element of %distance is a Class::Measure::Length object. So the following fix should work:

... print "\nAnd here comes the result of sorting the keys of that has +h\n"; my $sort_function = ($demo eq 'problem') ? sub { $distance{$b}->value <=> $distance{$a}->value } : sub { $distance{$b} <=> $distance{$a} }; for my $place (sort $sort_function keys %distance) { printf "%10s is %25.15f km from here\n", $place, $distance{$pl +ace}; } }

(Note that Class::Measure::Length inherits most of its methods from Class::Measure.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1137122]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2019-12-05 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (151 votes). Check out past polls.

    Notices?