Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl includes to reuse code.

by Tanktalus (Canon)
on May 30, 2016 at 14:30 UTC ( [id://1164509]=note: print w/replies, xml ) Need Help??


in reply to Perl includes to reuse code.

The error doesn't completely go away if you use Data::Dumper; in your Util.pm. The second option, print Data::Dumper(%HASH) line still won't work, because that's just not how perl works.

Instead, if you want to import things, whether implicitly (such as Dumper from the Data::Dumper module) or explicitly (such as gzip from IO::Compress::Gzip), and then make them available to any module that uses your module, you need to explicitly mark those symbols for export, either by providing your own import routine, or using the one from Exporter or other module that provides export functionality.

However, I would only really recommend doing this for truly global functions - ones that really will be used essentially everywhere. I've done this, but I really mean the things I put in there were well and truly global - such as strict, warnings, feature, and a number of other modules that I expected 90%+ of the rest of my modules to require (translation services and trace-logging). Other required modules I would prefer making explicit when and where needed, not to keep the memory usage down, but to help self-documentation: making things explicit. The above ones I put into a "policy.pm" file because it was our policy to follow strict, enable all warnings, enable perl features explicitly and commonly across the project, to support translation, and to trace nearly everything.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found