Sorting and undefined values

Earle Martin perl at downlode.org
Tue Dec 12 17:00:02 GMT 2006


Hello,

I have this code:

my @sorted = sort {
  $foo->{$a}->{'x'} cmp $foo->{$b}->{'x'} ||
  $foo->{$b}->{'y'} cmp $foo->{$b}->{'y'}
} keys %$foo;

This only produces the keys of items where 'x' is defined. What do I
need to do to sort first on 'x' if it's defined, and then on 'y', or
just 'y' if 'x' is undefined?

Thanks in advance,

Earle.

-- 
Earle Martin
            http://downlode.org/
http://purl.org/net/earlemartin/


More information about the london.pm mailing list