http://qs321.pair.com?node_id=1071519

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Is this possible? I have an object with a myList element. I would like to provide a client who uses the object the ability to use their own sorting routine. If they don't provide one, it fall backs to an internal sort routine. When I try to run my script, however, the fallback works as expected, but the $a and $b internal variables are undefined (they are not elements of $myList) in the client callback. Am I doing something wrong here or is this not possible? Thanks in advance.
##Object: sub _byCode { $a->asStringFmt() cmp $b->asStringFmt; } my $callback = $self->{sortCallback} || "_byCode"; ... foreach my $key (sort $callback @{$myList->getKeys}) { ... }
##Client: my $byCodeAndX = sub { .... }; my $obj = new Obj( sortCallback => $byCodeAndX )