Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: relaying sort's code block

by ikegami (Pope)
on Aug 18, 2014 at 22:21 UTC ( #1097917=note: print w/ replies, xml ) Need Help??


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 $@; ... }


Comment on Re: relaying sort's code block
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1097917]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-11-28 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (196 votes), past polls