Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 $@; ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1097917]
help
Chatterbox?
[james28909]: so if you subtracting as you loop, be aware that you will eventually be subtracting into a past month, or year <.<
[james28909]: dontcha love it!
[james28909]: Today would be scalar localtime. Yesterday would be scalar localtime - 1. sunday - monday would variate scalar localtime - ?
[james28909]: oops s/sunday - monday/sunday - saturday/
[james28909]: my mind is blown haha
[james28909]: hmm, i haz idea!

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-04-29 03:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.