Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Introsepcting the current Perl file via DATA, even w/o DATA?

by stevieb (Canon)
on Feb 05, 2016 at 02:26 UTC ( [id://1154460]=note: print w/replies, xml ) Need Help??


in reply to Introspecting the current Perl file via DATA, even w/o DATA?

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.

Replies are listed 'Best First'.
Re^2: Introspecting the current Perl file via DATA, even w/o DATA? ( __FILE__ )
by LanX (Saint) on Feb 05, 2016 at 15:22 UTC
    > 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.

    The penalty of reopening a file might be minimal nowadays, especially if it is still cached by the filesystem/ harddisk, but ...

    ... I'm not sure if __FILE__ is always holding something "openable".

    For instance consider the eval flag

    C:\>perl -e "print __FILE__" -e

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-23 09:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found