BluePerl has asked for the wisdom of the Perl Monks concerning the following question:

Maybe a simple Question: I use a dozen of scripts. Each of them uses a pile of the same uses. How can I achive to have just one file with all the uses which I can import? Here an Example

# obligigatory.pm # all my uses, which I needed in the other files # no package marker use strict; use warnings; use foo::bar; 1;
The main code goes here:
use obligatory; # use all the staff I needed $a = $b; # should give me an error/warning

Replies are listed 'Best First'.
Re: How to use a bunch of uses with just one use?
by Athanasius (Archbishop) on Aug 07, 2015 at 07:53 UTC

    Hello BluePerl,

    Just a side note on this:

    $a = $b; # should give me an error/warning

    Actually, that’s a bad example:

    17:47 >perl -Mstrict -Mwarnings -e "$a = $b; print qq[Bye!\n];" Bye! 17:48 >

    $a and $b are “special package variables” used by sort and so not subject to the usual declaration rules. See perlvar.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Hi, Thank you for your answer. My Question was about how to aggregate uses in one package and spread them acros my project. My example above was just to explain the problem. CPAN-s Toolkit module is close to my needs (see my answers below). Do you have a better solution? Best regards Blueperl
Re: How to use a bunch of uses with just one use?
by Corion (Patriarch) on Aug 07, 2015 at 06:19 UTC

    Personally, I like the list of modules to be explicit, but there is Toolkit to manage your own list of "default" modules.

      Toolkit is a source filter, so the usual caveats apply.

      I personally like explicit module mention, too, but I have

      package y; use Exporter qw (import ); our @EXPORT = qw ( &foo ); # exported functions my $callpack = ( caller )[0]; eval <<"EOH"; package $callpack; use Data::Dumper; use B::Deparse; # other modules... EOH sub foo { ... } 1;

      which allows me to

      #!/usr/bin/Perl use strict; use warnings; use y;

      or on the command line

      qwurx [shmem] ~> perl -My -nle 'dwim $_' somefile

      having all defaults in place. Pragmas like strict and warnings should always be explicit.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Thank you for your answer. Toolkit could be an option. I would prefer to have something similar to Toolkit. I need to have those obligatory modules only for some projects and not for each and every one.

Re: How to use a bunch of uses with just one use?
by shmem (Chancellor) on Aug 07, 2015 at 12:50 UTC
    # obligigatory.pm # all my uses, which I needed in the other files # no package marker use strict; use warnings; use foo::bar; 1;

    Be aware that strict and warnings are compiler directives which apply to the current scope only, be that eval, block or file.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: How to use a bunch of uses with just one use?
by soonix (Chancellor) on Aug 07, 2015 at 10:45 UTC