package Sortable; use overload 'cmp' => \&_cmp; sub _cmp { $_[0]->cmp($_[1]); } 1; #### package AnonArray; # Quick demo of how Sortable works use Sortable; @ISA = ('Sortable'); sub cmp { my $self = shift; my $other = shift; my $len = @$self > @$other ? @$self : @$other; for (0..($len - 1)) { if (my $res = $self->[$_] cmp $other->[$_]) { return $res; } } if ($len < @$self) { return 1; } elsif ($len < @$other) { return -1; } else { return 0; } } sub new { my $class = shift; return bless [@_], $class; } 1; #### @sorted = sort @to_sort;