Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Sorting by the hash value

by cybear (Monk)
on Jul 29, 2002 at 10:32 UTC ( [id://185940]=note: print w/replies, xml ) Need Help??


in reply to Re: Sorting by the hash value
in thread Sorting by the hash value

"To be civilized is to deny one's nature."
Denying ones nature is the key to being human.

Concerning "Sorting by the hash value":
It is difficult to advise you without knowing exactly what
you are trying to do, but if you are trying to print a
sorted list of values couldn't you just:

@keys = keys{%hash}; foreach $key (@keys) { $value = %hash{$key}; push(@values, $value); } sort(@values); print "@values\n";

Replies are listed 'Best First'.
Re: Re: Re: Sorting by the hash value
by shotgunefx (Parson) on Jul 29, 2002 at 11:09 UTC
    Are you replying to the root node? My kludge is to get around the fact that CGI.pm has the hash ordering (which is no order) when you use the -lables argument. I often need to use labels and tie'ing is easier than sublassing CGI.pm.

    As an aside, your code is overcomplicated.
    print sort values %hash;


    -Lee

    "To be civilized is to deny one's nature."
      Cool. I didn't know that you could do that.

      - cybear

Re: Re: Re: Sorting by the hash value
by Anonymous Monk on Oct 17, 2002 at 22:25 UTC
    Isn't this supposed to be:
    @keys = keys{%hash}; foreach $key (@keys) { $value = $hash{$key}; # notice $ versus % here push(@values, $value); } sort(@values); print "@values\n";

    Otherwise, I think you get an error such as:
    Can't use subscript on private hash at foo.pl line 123, near "$key}" (Did you mean $ or @ instead of %?) BEGIN not safe after errors--compilation aborted at foo.pl line 123.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found