Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2016-10-21 22:54 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.