Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, keepers of Perl knowledge!
I have code where I am constructing the name of a .conf file based on the location of the module:
package Module; use warnings; BEGIN { my $pathname = $INC{$\(__PACKAGE__)}.pm"}; $pathname =~ s/\.pm$/.conf/; } 1;
When I check the syntax via the interpreter, I get a warning:
$ perl -c Module.pm Use of uninitialized value in substitution (s///) at Module.pm line 8. Module.pm syntax OK $
If I comment out the use warnings; pragma, the warning goes away.
I'm assuming that __PACKAGE__ is not defined until a script loads the module, so this might be an explanation. perlmod states that using __PACKAGE__ can be thorny when creating variable names, so I thought I would pose the question to you. Should I be looking at another method to construct a variable name?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: a few questions about __PACKAGE__
by ikegami (Patriarch) on Feb 10, 2012 at 20:11 UTC | |
|
Re: a few questions about __PACKAGE__
by Eliya (Vicar) on Feb 10, 2012 at 20:00 UTC | |
|
Re: a few questions about __PACKAGE__
by Anonymous Monk on Feb 10, 2012 at 19:58 UTC | |
by Anonymous Monk on Feb 11, 2012 at 15:36 UTC | |
|
Re: a few questions about __PACKAGE__
by JavaFan (Canon) on Feb 12, 2012 at 10:54 UTC |