in reply to Accessing the __DATA__ blocks of other packages
No need for eval or other heavy artillery.
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.package TMPL; sub fodus { local $/; my $out = <($main::{+(caller)[0]."::"}->{DATA})>; # ... return $out; }
Makeshifts last the longest.
|
---|
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 |
In Section
Seekers of Perl Wisdom