[Pdx-pm] sort issues.
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
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:
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
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'
| $ perl -lwe '%h = ( "1.1" => "foo", "1.10" => "bar" ); $, = "|"; print %h'
More information about the Pdx-pm-list