in reply to How to set a set of our and @EXPORT variables concisely?
I'd just go with the use vars approach. Your only mistake was not initializing your variables at compile time. This is a very common mistake and is often misdiagnosed.
use base qw( Exporter ); our @EXPORT; BEGIN { @EXPORT= qw( $MC_CONFIG_DBI_DRIVER $MC_CONFIG_DB_NAME $MC_CONFIG_DB_USER $MC_CONFIG_DB_PWD $MC_CONFIG_FILE $MC_CONFIG_FEED_LOGS $MC_CONFIG_ARCHIVE_LOGS ); } use vars @EXPORT;
You see, in your original code, the my @var declares the @var array at compile time but doesn't initialize it (fill it with values) until run time. But use vars happens at compile time so you end up passing use vars an empty array.
The our trick can only half work since the "create lexical alias" part of our only has effect until the end of the current scope. So your map might be able to declare a bunch of package globals for you but the lexical aliases to them would disappear at the end of the enclosing block (either the block in the map statement or the next one -- I'd have to test to say for sure). But to get that to work probably requires eval, which also forces an enclosing block so there is no way to script doing our on a list of variable names unless you want to enclose almost your entire module inside an extra eval.
- tye (but my friends call me "Tye")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: How to set a set of our and @EXPORT variables concisely?
by princepawn (Parson) on Nov 21, 2000 at 19:03 UTC | |
by tye (Sage) on Nov 21, 2000 at 20:34 UTC | |
|