Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Filehandle of the current sourcecode, pointing after last code line?

by Anonymous Monk
on Oct 12, 2014 at 17:31 UTC ( [id://1103552]=note: print w/replies, xml ) Need Help??


in reply to Filehandle of the current sourcecode, pointing after last code line?

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

  • Comment on Re: Filehandle of the current sourcecode, pointing after last code line?
  • Download Code

Replies are listed 'Best First'.
Re^2: Filehandle of the current sourcecode, pointing after last code line?
by LanX (Saint) on Oct 12, 2014 at 20:19 UTC
    Thanx, that's what I expected... :-/

    The only way I see to fix the bug in Deparse is to compare the possible DATA handles (which are already at the right position) with the content if $0 / __FILE__ .

    Not elegant though...

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103552]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-24 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found