I dedicated a few hours to this today to see if there's a way to explicitly gain access to and modify the __DATA__ target into existence, when it wasn't explicitly defined, or gain access to $0 without opening it.

I tried all manner of hacking the Symbol Table, trying to force things into position, tried to merge the current running script into something that could be used, and alas, I honestly think it can't be done the way you desire.

I agree with AnonymousMonk, that you're going to have to load __FILE__. Do it in BEGIN, stash the results, and deal with the penalty.

I have modules that'll do this, but your efficiency goes down the toilet.

Discipulus said "I hope to hear working solutions but i humbly suspect we'll not", and I agree. I have one module that does deep file 'stuff', but from what I can tell, there's no way to hack a file handle to point to the current running script without opening it directly (I'm hoping with all I have that someone will direct us to a different understanding).

I keenly await responses from those who might be able to correct this understanding, through perhaps perlapi, symtab or otherwise.

Good question.


In reply to Re: Introsepcting the current Perl file via DATA, even w/o DATA? by stevieb
in thread Introspecting the current Perl file via DATA, even w/o DATA? by LanX

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.