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