So I have a Perl class. It has a sort() method, and I want it to be more or less identical to the built-in sort() function:
$object->sort(sub ($$) { $_[0] <=> $_[1] });
But I can not:
$object->sort(sub { $a <=> $b });
Due to visibility. But the List :: Util module does this with reduce() . I looked at the List :: Util module and they did some nasty things with no strict 'vars' to make this happen. I tried this, but to no avail.
As far as I understand, reduce() works the way it happens, because it is exported to the corresponding namespace, and therefore my class cannot do this, since the function is pretty firmly in another namespace. Is this right, or are there some (undoubtedly more disgusting and unscrupulous) ways to do this in my situation?
scope class perl
Chris lutz
source share