Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to "use" multiple modules with one "use"?
    primarykey
    data
    text
    <p>I want use some packages and some pragmas in all my programs, like:</p> <pre><code>use 5.014; use warnings; use autodie; use My::ModuleA::Something; use ModuleB qw(Func1 Func2); </code></pre> <p>I don't want repeat myself in every module, so looking for a way how to make one package e.g. <code>My::Common</code> what will contain the above packages and in my programs do only:</p> <pre><code>use My::Common; say Func1("hello"); #say enabled and Func1 imported in the My::Common </code></pre> <p>how to achieve this?</p> <p>The was read <code>preldoc -f use</code> and <code>perldoc perlmodlib</code> so i think I must "somewhat" to do this with BEGIN plus require&amp;import, but absolutely don't know how.</p> <hr> <p><strong>UPDATE:</strong> I'm already tried the basic things.</p> <p>With <code>require</code> - my prg.pl program.</p> <pre><code>require 'mymods.pl'; $var = "hello"; croak "$var\n"; </code></pre> <p>mymods.pl contain</p> <pre><code>use strict; use feature 'say'; use Carp qw(carp croak cluck); 1; </code></pre> <p>DOES NOT WORKS. Got error:</p> <pre><code>$ perl prg.pl String found where operator expected at prg.pl line 3, near "croak "$var\n"" (Do you need to predeclare croak?) syntax error at prg.pl line 3, near "croak "$var\n"" Execution of prg.pl aborted due to compilation errors. </code></pre> <hr> <p>with "use My":</p> <pre><code>use My; $var = "hello"; croak "$var\n"; </code></pre> <p>my My.pm</p> <pre><code>package My; use strict; use feature 'say'; use Carp qw(carp croak cluck); 1; </code></pre> <p>DOES NOT WORKS either. Got the same error.</p> <hr> <p>Any working idea?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload