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

Re: package and do

by ikegami (Patriarch)
on Feb 03, 2006 at 04:52 UTC ( [id://527535]=note: print w/replies, xml ) Need Help??


in reply to package and do

The following is even simpler:
my $pkg = 'Foo'; my $foo = do { local $/; eval "<${pkg}::DATA>" };

The following is a version that doesn't use eval EXPR (faster, safer):

my $pkg = 'Foo'; my $data_fh = do { no strict 'refs'; *{"${pkg}::DATA"} }; my $foo = do { local $/; <$data_fh> };

And if you want to cut your memory usage in half, use the following:

my $pkg = 'Foo'; my $data_fh; { no strict 'refs'; $data_fh = *{"${pkg}::DATA"}; } my $foo; { local $/; $foo = <$data_fh>; }

You could even combine the two blocks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-03-28 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found