Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: How can I access object data in a user defined sort cmp function? (OOP)

by LanX (Sage)
on Jan 28, 2015 at 17:24 UTC ( #1114790=note: print w/replies, xml ) Need Help??


in reply to Re^2: How can I access object data in a user defined sort cmp function?
in thread How can I access object data in a user defined sort cmp function?

> I want more than simply sorting the keys. Based on the keys I have to look up something within the object based on which I can sort the keys. For this I have to access the object's variables. Currently I create a global variable called $sort_self and I set this manually before calling the user defined cmp function byvalue, but this seems very unelegant.

it is not very elegant, b/c - sorry - you are violating OOP and encapsulation.

The best design is to add a method %keys=$obj->sort_keys_by_val() which returns your keys.

No need to tunnel $self artificially cause $self will be the first argument.

update

the code for this method can be taken from here

Cheers Rolf

PS: Je suis Charlie!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2022-01-22 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?