Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Re: Accessing the __DATA__ blocks of other packages

by pfaut (Priest)
on Dec 11, 2002 at 22:39 UTC ( [id://219203]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Accessing the __DATA__ blocks of other packages
in thread Accessing the __DATA__ blocks of other packages

I would say that what you are doing is probably not a very good software design. If you need something from your caller, it's probably a better idea to have the caller pass it as an argument. That way, it's documented that the called routine is using it. Using backdoor methods such as this to get information from the caller leads to unmaintainable code. Make sure you document this behavior so that anyone that uses this code in the future knows their DATA handle is going to be used when they call this method.

With that said, if you really need to do it without modifying the calling code, try this.

sub called { my $caller = (caller)[0]; my $fh = eval '\*'.$caller.'::DATA'; my $data = <$fh>; print "read: $data\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-18 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found