in reply to Re: anonymous sub, packages, global variables
in thread anonymous sub, packages, global variables

*p2::func = \$func;

sorry but thats nonsense, your assigning a coderef to the scalar slot of the glob, not to the code slot!

update:

DB<101> $coderef=sub {print "nonsense"} DB<102> *glob=\$coderef DB<103> &$glob nonsense DB<104> glob()

Cheers Rolf

Replies are listed 'Best First'.
Re^3: anonymous sub, packages, global variables
by wind (Priest) on May 17, 2011 at 18:49 UTC

    Exactly, because he wanted to be able to call his function using $func->() in package p2 just like in p1. I therefore showed how how to achieve both potentially desired results: being able to call his function like func() or by $func->() like he had in his code.

    I wouldn't advocate either methods, but it's what he asked for.

      OK sorry, after rereading the OP's code I see the whole question is bizarre.

      He seems to want a function to work on variables from the current package of the caller's context...

      Cheers Rolf