Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Accessing the __DATA__ blocks of other packages

by caedes (Pilgrim)
on Dec 11, 2002 at 22:19 UTC ( [id://219196]=note: print w/replies, xml ) Need Help??


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

I originally had the calling code slurp the __DATA__ into a scalar and then pass that to the other package's subroutine, however I don't want to have to do this for every package that wants to call the package that uses __DATA__.

-caedes

  • Comment on Re: Re: Accessing the __DATA__ blocks of other packages

Replies are listed 'Best First'.
Re: Re: Re: Accessing the __DATA__ blocks of other packages
by pfaut (Priest) on Dec 11, 2002 at 22:39 UTC

    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://219196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found