Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

multiple modules

by jesuashok (Curate)
on Oct 28, 2005 at 04:26 UTC ( #503546=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

why perl doesn't have option of including many modules in a single line as follows :- use stict,warnings;

Definitely some Monks will have the answers for this. I am awaiting for your reply.

"Keep pouring your ideas"

Comment on multiple modules
Re: multiple modules
by BrowserUk (Pope) on Oct 28, 2005 at 04:51 UTC

    You could write your own:

    package all; sub import { shift; my $caller = caller(); my $code = "package $caller; use " . join '; use ', @_; eval $code; } 1;

    And then use it like this:

    use all qw[strict warnings Time::HiRes Data::Dumper List::Util];

    Unfortunately, there is no way to specify an import list for each module, so you get everything that they export, which could be nothing at all for some modules, or much more than you wanted, or just not what you need. Eg. No way to tell List::Util that you want to use sum()

    Fixing that is left as an exercise for the reader :)


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      That doesn't work for strict and warnings, which wind up applying only within the eval. I discuss how to make that and the import lists work in Bundling commonly-used modules into a toolset.

      package all; use base 'ToolSet'; ToolSet->set_strict(1); ToolSet->set_warnings(1); ToolSet->export( 'Time::HiRes' => undef, 'Data::Dumper' => undef, 'List::Util' => 'sum', ); 1;

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: multiple modules
by chromatic (Archbishop) on Oct 28, 2005 at 06:56 UTC

    Perl can't tell if you intend to pass arguments to the import() method of a module this way. However, consider using Toolkit.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://503546]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-12-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls