Skip to content

Instantly share code, notes, and snippets.

/sort.pl Secret

Created August 5, 2014 14:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/b6f1f93ca5c49b9bbe15 to your computer and use it in GitHub Desktop.
sub sort {
my ($self, $cb) = @_;
return $self->new(sort @$self) unless $cb;
my $caller = caller;
no strict 'refs';
return $self->new(
sort {
local (*{"$caller\::a"}, *{"$caller\::b"}) = (\$a, \$b);
$a->$cb($b)
} @$self
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment