use variable from other module

In module bait we have

our %IMAGEPADV = (
'SxRT-5.1' => [ qw(sol_sparc sol_x64) ],
'LxRT-5.1' => [qw(rhel5_x86_64 sles10_x86_64 sles11_x86_64)],
...
);

In my own module use this to access %IMAGEPADV

%bait::IMAGEPADV

2 Comments

Hi Michael

That might be true, but one of the many reasons for using modules is to stop this sort of gratuitous invasion of the module's namespace and variables.

So, a well-written module will provide a documented method to access data it wants users to access, and will expect users to not write code (as you've done) which is rigged to rely on knowing the internal structure of the module.

In short: Don't do that!

Any good Perl introductory text will warn you against using and promoting such nasty code.

It's incumbent upon all Perl coders to not use such code, and to train ourselves to politely recommend other people don't do it either.

Cheers
Ron

In addition to Ron's comments, it's best to avoid all lowercase package names. Those are usually reserved for pragmas, which are generally considered part of perl itself.

Leave a comment

About Michael Li

user-pic I blog issues resolved at work