Created
May 21, 2017 20:45
-
-
Save andrewsolomon/e1b187c09c042b5cd6442ee7f48d8cf7 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/perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
use Data::Dump 'pp'; | |
my @arr = ([1 .. 6], [1,2,3] , ['a' .. 'h']); | |
sub by_arr_length { | |
return 1 if scalar(@$a) > scalar(@$b); | |
return -1 if scalar(@$a) < scalar(@$b); | |
return 0; | |
}; | |
my @barr = sort by_arr_length @arr; | |
say 'Unsorted: '.pp(\@arr); | |
say 'Sorted: '.pp(\@barr); | |
# @barr should now be ([1, 2, 3], [1 .. 6], ["a" .. "h"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment