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!
In reply to Re: Numeric Sorting on Characters
by Kenosis
in thread Numeric Sorting on Characters
by halecommarachel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |