Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Ben Tilly
What our does is binds the package variable to lexical scope. So a package after an our doesn't change the variable. But if you have the our *after* the package then it will bind the correct package. So in your eval put the package statement before our %map and you'll be fine. Incidentally if

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Uri Guttman
On 10/29/2014 02:47 PM, Morse, Richard E.,MGH wrote: Hi! I'm running into an odd desire, and I'm hoping someone here can at least tell me where to look, as so far Google and DDG are not telling me what I want. I have a bunch of modules which have the same subroutines in each. Mostly, the code

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Morse, Richard E.,MGH
On Oct 29, 2014, at 2:56 PM, Uri Guttman u...@stemsystems.com wrote: hi ricky, i am somewhat confused as to your goal. you want each sub to use a common %map? why not have them access it directly from the base package? Hi! There are actually three different package variables that contain

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Morse, Richard E.,MGH
Thanks -- I see how to do this with a string eval, but I'm hoping to avoid having to keep the functions as text strings. If I can't find any other way, it's what I will have to fall back on, but I'm hoping there's some way to avoid this. Ricky On Oct 29, 2014, at 2:56 PM, Ben Tilly

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Mike Small
Morse, Richard E.,MGH remo...@mgh.harvard.edu writes: I've tried various things, but from what I can understand, even with everything declared our, the sub definition closes over the package that it's in when defined. I've seen references to doing an `eval (package $package; sub handle_ages {

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Morse, Richard E.,MGH
On Oct 29, 2014, at 3:12 PM, Mike Small sma...@panix.com wrote: What about having a method that returns a reference to your map that you override in each of the derived classes? e.g. ... package PKG::_base; sub _map { die; } sub handle_ages { ; } sub handle_dests

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Uri Guttman
On 10/29/2014 03:07 PM, Morse, Richard E.,MGH wrote: On Oct 29, 2014, at 2:56 PM, Uri Guttman u...@stemsystems.com wrote: hi ricky, i am somewhat confused as to your goal. you want each sub to use a common %map? why not have them access it directly from the base package? Hi! There are

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Ben Tilly
In a block you can do: no strict 'refs'; my $mapref = \%{$package\::map}; And now you have a lexical reference that will bind to a closure. Do note that using objects here is more common. On Wednesday, October 29, 2014, Morse, Richard E.,MGH remo...@mgh.harvard.edu wrote: Thanks -- I

Re: [Boston.pm] Help with symbol table munging...

2014-10-29 Thread Mike Small
Morse, Richard E.,MGH remo...@mgh.harvard.edu writes: Thanks, except I'm not in an object context. Sorry, I should read more carefully. Well, what about if the base module's functions take the reference to the map as an argument and your symbol table munging instead of assigning the functions