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

In reply to RE: Re: How do I get the name of the file from which the class was loaded? by Rudif
in thread How do I get the name of the file from which the class was loaded? by Rudif

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.