Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Sorting - lower to upper

by pelagic (Priest)
on Jul 15, 2004 at 15:51 UTC ( [id://374697]=note: print w/replies, xml ) Need Help??


in reply to Sorting - lower to upper

use strict; use Data::Dumper; my %h = ( 'John' => 'P9111', 'Bob' => 4711, 'xavier' => '20040610', 'alice' => '20040610', ); my %sk = map ({$_, ($_ =~ m/^[a-z]/) ? 0 : 1} (keys %h)); print Dumper %sk; my @xk = (sort {$sk{$a} <=> $sk{$b} || $a cmp $b} keys %sk); print Dumper @xk; ___OUTPUT___ $VAR1 = 'Bob'; $VAR2 = 1; $VAR3 = 'alice'; $VAR4 = 0; $VAR5 = 'John'; $VAR6 = 1; $VAR7 = 'xavier'; $VAR8 = 0; $VAR1 = 'alice'; $VAR2 = 'xavier'; $VAR3 = 'Bob'; $VAR4 = 'John';

pelagic

Replies are listed 'Best First'.
Re^2: Sorting - lower to upper
by revdiablo (Prior) on Jul 15, 2004 at 19:03 UTC

    Instead of using Dumper as you have:

    print Dumper %sk; print Dumper @xk;

    You might consider using it like so:

    print Dumper \%sk; print Dumper \@xk;

    You should find the output a bit more sensible.

      Yeah, thanks, that was actually a typo. I always use the reference with Dumper.

      pelagic

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found