What's wrong? It doesn't work, but it can be fixed.
__FILE__ is the special literal that I need, not __FILENAME__.
This works:
#! perl -w
use strict;
package This::Module;
our $_Filename = __FILE__;
# ...
package main;
print "$This::Module::_Filename\n";
I found this in perldata (which I should have read beforehand)
The special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that
point in your program.
However, after I replaced __FILENAME__ by __FILE__ in your code,
I had trouble getting the constant out of the package.
#! perl -w
use strict;
package This::Module;
use CONSTANT _Filename => __FILE__;
# ...
package main;
#print "$This::Module::_Filename\n";
#Use of uninitialized value in concatenation (.) at getfilename1.pl li
+ne 10.
print " @{[ This::Module::_Filename ]}\n";
#Bareword "This::Module::_Filename" not allowed while "strict subs" in
+ use at getfilename1.pl line 13.
Now I am a little lost. Questions:
What is the syntax for getting a package constant outside the package? Should I export it?
Is 'use CONSTANT' same as 'use constant', from constant.pm?
TIA
Rudif
| [reply] [d/l] [select] |
use vars qw(_Filename);
_Filename = __FILE__;
Sorry for the wild goose chase.
-- Randal L. Schwartz, Perl hacker
Update: OK, I give up on this thread. See the right way to do it, below. {grin} | [reply] [d/l] |
>Something more like this is gonna work a whole lot better.
> use vars qw(_Filename);
> _Filename = __FILE__;<br>
... yes, after a tweak or two ;-)
use strict;
use vars qw( $_Filename );
$_Filename = __FILE__;
print $_Filename;
Rudif
| [reply] [d/l] [select] |