http://www.perlmonks.org?node_id=1097917


in reply to relaying sort's code block

1) The code you posted doesn't exhibit the problem, and 2) the complaint is different that what you say it is.

The problem is found in code of the following form:

package Foo; sub sort($&) { my ($self, $cmp) = @_; ... my @sorted = sort $cmp @list; <-- sort compiled in one package ... } package Bar; Foo->sort({ $a cmp $b }); <-- Sub compiled in another

sort sets $a and $b of the package in which the sort is present.

The simplest solution (while continuing to use $a and $b) is

package Foo; sub sort($&) { my ($self, $cmp) = @_; ... my $caller = caller; my @sorted = eval("package $caller; sort \$cmp \@list"); die $@ if $@; ... }