Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: our scope and packages

by tilly (Archbishop)
on Aug 28, 2008 at 23:01 UTC ( [id://707623]=note: print w/replies, xml ) Need Help??


in reply to our scope and packages

Your problem is that Perl scopes according to packages. It is not that %prod is in a different file. It is that it is in a different package. The cheesy solution is to just make %prod in your current package be the copy in the root package, which is called main:
*prod = \%main::prod; our %prod;

Replies are listed 'Best First'.
Re^2: our scope and packages
by jfrm (Monk) on Aug 28, 2008 at 23:12 UTC

    Thank you; it all sounds highly feasible. However, this is unfamiliar territory. Should I be putting this statement *prod = in the originating file (it isn't an OO package - at least I don't think it is) where %prod is populated or should I be putting it in the package that currently can't access it? Or both?

    thanks a lot for your help.

      In the package that currently can't access it.

      Actually the really right way to do it is to move %prod into a configuration module that might look like this:

      package My::Configuration; use strict; use Export qw(import); our @EXPORT_OK = qw(%prod); our %prod = ( ... ); 1;
      and then somewhere in main and in your other package insert the line:
      use My::Configuration qw(%prod);
      Doing that you won't even need the our declaration because importing it declares it.
        Thanks, you've no idea how happy fixing this has made me. I could kiss you. (but this might be a result of living for so long with hundreds of men in brown gowns).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-24 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found