Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Hash value sorting

by daxim (Chaplain)
on Aug 14, 2012 at 13:44 UTC ( #987358=note: print w/replies, xml ) Need Help??

in reply to Re^2: Hash value sorting
in thread Hash value sorting

That code collides with your explanation of the data structure in 987336. Only one can be correct.

In the constructor I see you initialise the field _counts with a hash reference. Where do you now get a scalar reference from?

It would help if you dump $self before sorting, so we can see what the data structure really looks like.

use Data::Dumper; print Dumper $self;

Replies are listed 'Best First'.
Re^4: Hash value sorting
by iHutch105 (Initiate) on Aug 14, 2012 at 15:41 UTC

    You're absolutely right and I've found the problem.

    I made a mistake whenever I was creating/adding to values in the hash. I had this line:

    ${$self->{_counts}{$key}} += $value;

    This was where the scalar ref was coming from. I should note, key and value are parameter passed in, representing the obvious. This line explains why I had to do some extra, dodgy dereferencing later on and, of course, should have read:

    $self->{_counts}{$key} += $value;

    All seems to be sorted now. Code looks a lot tidier too. First time I've really used references much but it's been a good learning experience.

    Thanks to all for the help and suggestions.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987358]
[Discipulus]: someone has experience with this? as destiation i think i'll go with virtualbox on centos
[Lady_Aleena]: Why XP?
[Discipulus]: it is for my father: it is impossible to tell him to learn a newer OS
[Lady_Aleena]: To tell him or teach him?
Discipulus anyway xp is still the best lowend game machine
[Discipulus]: both: everyting must be identical in the new v-machine
[Lady_Aleena]: So putting a nice DE or WM up on a Linux machine is not an option?
[Discipulus]: i need some converter to have directly an OVF format directly: at the moment i'm trying with vmware converter standalone

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-05-22 18:38 GMT
Find Nodes?
    Voting Booth?