Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:
I have a module that should be capable of auto-exporting, via the import() sub, an initialized variable, $VAR, via a typeglob i.e. not via Exporter, into the useing packages namespace. At its simplest (I'm afraid that I'm not at liberty to divulge the exact details), my module code is along the lines of ...
The variable is, indeed, set i.e. I see "Some_val" c/w "Something's wrong", if the declaration is made thus...use warnings; use strict; package Package; my $Val; sub import { Val = qw/some_val/; my $caller = caller; no strict qw/refs/; *{"$caller\::VAR"} = *Val; } 1;
My question now is, what have I overlooked such that cases where the variable declaration is made in a list work e.g. neither of the following 2 cases work...use Package; our $VAR; warn $VAR;
oruse Package; our ($VERSION, $VAR); warn $VAR;
In both of the above cases, I see the "Something's wrong" warning.use package; our ($VAR, $VERSION); warn $VAR;
Any thoughts/insights etc. gratefully received
TIA ,
Further update:
Code will never run without relaxing <C>strict refs<C/> ... doh!!
Update:
Add clarification thanx to choroba who was good enough to point out the lack of clarity in the OP.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: glob'ing and variable setting
by choroba (Cardinal) on Dec 31, 2013 at 15:02 UTC |