LPM: The times they are a-changin' (or: integer hash keys)

Graydon Dodson grdodson at lexmark.com
Tue Aug 21 17:48:49 CDT 2001



  I am confused as to why this is "hard".  This is a simple numeric sort from 
the old "pink camel book" days.
  
The following works just fine for me:


----------------------------------------------------
#!/usr/bin/perl -w

use strict;

my %nums = (
	1 => 'one',
	2 => 'two',
	10 => 'ten',
	20 => 'twenty'
	);

sub numericaly { $a <=> $b };

print "The numeric way...\n";

foreach my $num (sort numericaly keys %nums) {
	print "$num ($nums{$num})\n";
}
-----------------------------------------------------



Graydon Dodson                grdodson at lexmark.com
Lexmark International Inc.




More information about the Lexington-pm mailing list