Numeric sort
#!/usr/bin/perl
use strict;
use warnings;
sub numerically {
$a*1.0 <=> $b*1.0 or $a cmp $b
};
my @words = qw(1e2 2e1 3 4 5);
print 'Normal sort: ', join(', ', sort @words), "\n";
print 'Numeric sort: ', join(', ', sort numerically @words), "\n";
Related examples in the same category