Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Accessing the __DATA__ blocks of other packages

by Aristotle (Chancellor)
on Dec 14, 2002 at 23:53 UTC ( #219916=note: print w/ replies, xml ) Need Help??


in reply to Accessing the __DATA__ blocks of other packages

No need for eval or other heavy artillery.

package TMPL; sub fodus { local $/; my $out = <($main::{+(caller)[0]."::"}->{DATA})>; # ... return $out; }
The key here is that Perl makes the symbol table of each package available as a hash called %%packagename:: - with %main:: containing keys for all packages including itself, the value being a glob pointing in turn to that package's symbol table. So I use %main:: to get the glob to the caller's package, then dereference it as a hash, fishing the DATA key from it in turn.

Makeshifts last the longest.


Comment on Re: Accessing the __DATA__ blocks of other packages
Download Code
Replies are listed 'Best First'.
Re: Re: Accessing the __DATA__ blocks of other packages
by pfaut (Priest) on Dec 15, 2002 at 00:02 UTC

    Sneaky. (I've stashed it away for possible future use.)

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2015-07-31 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls