in reply to Numeric Sorting on Characters
If you're using Perl v5.14+, you could use the r (for return the modified string) modifier in a substitution:
use strict; use warnings; my %hash = map { $_ => 1 } qw/987-665-888 456-123-000 000-000-000 123- +456-789/; print "$_\n" for sort { $a =~ s/-//gr <=> $b =~ s/-//gr } keys %hash;
Output:
000-000-000 123-456-789 456-123-000 987-665-888
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Numeric Sorting on Characters
by AnomalousMonk (Archbishop) on Aug 14, 2013 at 23:22 UTC | |
by locked_user sundialsvc4 (Abbot) on Aug 15, 2013 at 13:24 UTC |