Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created March 8, 2016 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsolomon/65b795be10da569f878d to your computer and use it in GitHub Desktop.
Save andrewsolomon/65b795be10da569f878d to your computer and use it in GitHub Desktop.
#!/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