[Pdx-pm] sort issues.

Tkil tkil at scrye.com
Fri Aug 30 14:08:23 CDT 2002


>>>>> "GR" == Gabrielle Roth <Roth> writes:

GR> 1. Obviously, the order isn't right.  I thought the <=> operator
GR>    would do a numerical sort, but apparently that's just for
GR>    integers?  I'm not any better off than if I just did a regular
GR>    sort.

The general case of this is the same problem as "sorting" the parts of
a document (or, more precisely, the outline of its headers).  This
came up on #perl a few years back:

   http://slinky.scrye.com/~tkil/perl/#rev-sort

Basically, you split each key into its parts, and then compare those
components in order from most significant to least significant.

I do wonder if, in this case, you could leverage the funky dot
notation that showed up in perl 5.6...  Well, maybe, but it looks
hairy.

GR> 2. One of (1.1|1.10) goes missing; I thought maybe because the
GR>    <=> evaluated them as equivalent, but it does this with the
GR>    "cmp" operator as well.  I tried quoting the keys, but that
GR>    didn't help either.

If it wasn't clear from the previous responses, you need to quote the
keys when you're constructing the hash:

| $ perl -lwe '%h = ( 1.1 => "foo", 1.10 => "bar" ); $, = "|"; print %h'
| 1.1|bar
| $ perl -lwe '%h = ( "1.1" => "foo", "1.10" => "bar" ); $, = "|"; print %h'
| 1.1|foo|1.10|bar

t.



More information about the Pdx-pm-list mailing list