Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: sorting a hash by keys, according to preference

by Tanktalus (Canon)
on Apr 13, 2005 at 03:57 UTC ( [id://447254]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    .4  .6  .1
    .3  .5  .1
    .0  .2  .1
    .5  .7  .1
    
  2. or download this
    my @keys = qw(start stop step);
    for my $type (@keys) {
      print $point->{$type}, "\t";
    }
    
  3. or download this
    my @keys = qw(start stop step);
    for my $type (@keys) {
      next unless exists $point->{$type};
      print $point->{$type}, "\t";
    }
    
  4. or download this
    my %weights = ( start => 10, stop => 20, step => 30 );
    for my $type ( sort { $weights{$a} <=> $weights{$b} } keys %$point ) {
      print $point->{$type}, "\t";
    }
    
  5. or download this
    my %weights = do { my $i = 0; map { $_ => $i++ } qw(start stop step ot
    +her stuff in order here) };
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found