[Pdx-pm] sort issues.

Michael P plumpy at krimedawg.org
Fri Aug 30 13:08:46 CDT 2002

On Fri, 30 Aug 2002, Roth, Gabrielle wrote:

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

A sort function like this would work:
sub verscmp {
  @a = split /\./, $a;
  @b = split /\./, $b;
  $a[0] != $b[0] ? $a[0] <=> $b[0] : $a[1] <=> $b[1];

First you compare the part before the decimal and if they're the same, you
compare the part after the decimal.  The key here, of course, is that you
DON'T want a numerical sort.  You want a fake version-number-style sort.

Remember, 1.12 IS less than 1.2!  Perl was doing it correctly, you're just
don't actually want a numerical sort.

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

The problem is that the value is getting chopped at hash creation time.
You need to do this (quoting the hash keys):
%portName = (
  "1.1" => "smith",
  "1.10" => "tagquitz",

More information about the Pdx-pm-list mailing list