Question : Is there a way to get this filehandle without specifying a __DATA__ or __END__ section, i.e. without reopening $0 and always pointing behind the last codeline after compilation (even if there is already a __DATA__ section defined)

No, I don't think so, only stuff like open DATA, '<', \'this works too';

Otherwise if I have defined DATA filehandles in various packages, can I check which file (if existent) is associated with it?

No, I don't think so, you cannot get filename from filehandle, there is no api and no guarantee there exists a filename, but %INC ought to have package/filename associations ...

Or if there is no pure Perl way to do it, is it possible to inspect this info with help of the B backend or other magic?

I don't know but I doubt it :)

if (tmp && tmp != KEY___DATA__ && tmp != KEY___END__

http://perl5.git.perl.org/perl.git/blob?f=t/io/data.t


In reply to Re: Filehandle of the current sourcecode, pointing after last code line? by Anonymous Monk
in thread Filehandle of the current sourcecode, pointing after last code line? 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.