Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Accessing the __DATA__ blocks of other packages

by Ovid (Cardinal)
on Dec 11, 2002 at 21:58 UTC ( [id://219190]=note: print w/replies, xml ) Need Help??


in reply to Accessing the __DATA__ blocks of other packages

I would recommend moving __DATA__ into a proper file. Otherwise, you can use a typeglob in your file with __DATA__ to export the data filehandle. You could also read the data from the handle, cache it, and return it to whomever wants it. Lastly, here's the answer to your question.

package Foo; 1; __DATA__ line 1 line 2

Save the above as Foo.pm and use the following test program:

#!/usr/bin/perl -w use strict; use Foo; print while (<Foo::DATA>);

I did not get any warnings running this, but if you do, you can always turn off warnings locally.

{ local $^W; print while (<Foo::Data>); }

Or better yet, if you use the warnings pragma:

{ now warnings 'once'; print while (<Foo::Data>); }

This is much better as it will only turn off the one warning, but leave others enabled.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

Replies are listed 'Best First'.
Re: Re: Accessing the __DATA__ blocks of other packages
by caedes (Pilgrim) on Dec 11, 2002 at 22:24 UTC
    While I don't doubt that your code works, I think you might have misunderstood me. To make your example like my problem, the package Foo would have a subroutine with the while(<main::DATA>), and the main script would have the __DATA__ token. This is really too simplified though because Foo doesn't know what it's caller is ahead of time (it's not always main).

    -caedes

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found