Created
March 8, 2016 22:29
-
-
Save andrewsolomon/65b795be10da569f878d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
use Data::Dump 'pp'; | |
# http://stackoverflow.com/questions/372370/how-can-i-split-a-string-into-chunks-of-two-characters-each-in-perl | |
sub funny_compare { | |
my ($n_a, $w_a) = ($a =~ m/(\d*)(\D*)/); | |
my ($n_b, $w_b) = ($b =~ m/(\d*)(\D*)/); | |
return $n_a <=> $n_b || $w_a cmp $w_b; | |
}; | |
my @random = ("123bab","93145sdjf","100aaa"); | |
my @ordered = sort funny_compare @random; | |
say pp @ordered; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment