> -----Original Message----- > From: David Garamond [mailto:[EMAIL PROTECTED]] > Sent: Friday, October 04, 2002 3:17 PM > To: Bob Showalter > Cc: [EMAIL PROTECTED] > Subject: Re: package name alias (for shorter variable name) > > > thanks for the answer, bob. > > Bob Showalter wrote: > > There's nothing that says the file Foo/Bar/Constants.pm > must have a "package > > Foo::Bar::Constants" declaration. > > true, and i've realized that. i come from a python background and by > contrast, in python, filename and directory name dictate the > package/namespace.
I should have clarified. Those *do* need to match if you're using Exporter. > > > But I think you'll find this kind of thing goes against the > spirit of how > > modules work. > > indeed. i still want to name my package Foo::Bar::Constants. > the 'X' (or > let's name it 'tmp') is just a temporary prefix to help ease my weary > typing hands. in python i can do something like this: > > import Foo.Bar.Constants > print Foo.Bar.Constants.alice > tmp = Foo.Bar.Constants > print tmp.alice > tmp2 = tmp > print tmp2.alice > > the three 'print' statements print the same thing. i had > thought that in > perl we can do some aliasing with the symbol table (the * and \* > stuffs)? this is one beast i have yet to understand. Yes, that's what Exporter does. > > > Another approach might be to stuff those values into a hash > and export just > > the hash: > > hm, i don't think i like this approach. i don't want to > hashify everything. OK, try this: Foo/Bar/Constants.pm -------------------- package Foo::Bar::Constants; require Exporter; @ISA = qw(Exporter); @EXPORT = qw($alice $bruce $charlie $devon); $alice = {name=>"Alice", low=>-10, high=>21}; $bruce = {name=>"Bruce Wayne", low=>-17, high=>5}; $charlie = {name=>"Charlie", low=>-3, high=>3}; $devon = {name=>"Devon E.", low=>1, high=>29}; 1; main program ------------ use Foo::Bar::Constants (); { package X; Foo::Bar::Constants->import } print $X::alice->{name}; # prints "Alice" Here your using the Exporter functionality, but exporting symbols into the "X" namespace instead of your current namespace. The empty parens on the "use" prevents the symbol imports into package main. (An alternative is to use @EXPORT_OK in the module and then just pass the @EXPORT_OK list to the call to import().) HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]