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

Re: reusable hash value sort

by Courage (Parson)
on Jul 13, 2002 at 07:04 UTC ( [id://181468]=note: print w/replies, xml ) Need Help??


in reply to reusable hash value sort

I can suggest a solution which is not good to use in programs, but meets your requirements.
my $current_href = {}; sub byValue { $current_href->{$a} cmp $current_href->{$a}; } # ... somewhere in your program $current_href = \%myHash;

Just assign hash ref to current hash in consideration

Courage, the Cowardly Dog.

Replies are listed 'Best First'.
Re: Re: reusable hash value sort
by jdavidboyd (Friar) on Jul 13, 2002 at 13:31 UTC
    Being a Perl newbie, I must ask,
    why is this "not good to use in programs"?
      I beleive it's better to create "independent" subroutines, in that sence of a word that they will not depend on a state of some external global variable. When you'll return to this subroutine after many years and will reuse it, then you have a chance to use it incorrectly.

      As a second point, you may accidentially break that external variable somehow and after that something bad will happen, including coredumps (AFAIK some versions of perl will coredump on sort routines when criteria subroutine does not behave well)

      Courage, the Cowardly Dog

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found