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 )
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: providing a callback routine to sort ( $::a $::b )
by Anonymous Monk on Jan 21, 2014 at 21:53 UTC | |
Re: providing a callback routine to sort
by pemungkah (Priest) on Jan 21, 2014 at 22:04 UTC | |
by Anonymous Monk on Jan 21, 2014 at 22:41 UTC | |
by pemungkah (Priest) on Jan 23, 2014 at 03:29 UTC | |
Re: providing a callback routine to sort
by Anonymous Monk on Jan 21, 2014 at 23:01 UTC | |
Re: providing a callback routine to sort
by Laurent_R (Canon) on Jan 21, 2014 at 23:26 UTC | |
by Anonymous Monk on Jan 22, 2014 at 04:17 UTC | |
by Anonymous Monk on Jan 22, 2014 at 14:24 UTC |
Back to
Seekers of Perl Wisdom