Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created May 21, 2017 20:45
Show Gist options
  • Save andrewsolomon/e1b187c09c042b5cd6442ee7f48d8cf7 to your computer and use it in GitHub Desktop.
Save andrewsolomon/e1b187c09c042b5cd6442ee7f48d8cf7 to your computer and use it in GitHub Desktop.
#!/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