Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:12:52+00:00 2026-05-23T11:12:52+00:00

I want use some packages and some pragmas in all my programs, like: use

  • 0

I want use some packages and some pragmas in all my programs, like:

use 5.014;
use warnings;
use autodie;
use My::ModuleA::Something;
use ModuleB qw(Func1 Func2);

I don’t want repeat myself in every module, so looking for a way how to make one package e.g. My::Common what will contain the above packages and in my programs do only:

use My::Common;
say Func1("hello"); #say enabled and Func1 imported in the My::Common

how to achieve this?

The was read preldoc -f use and perldoc perlmodlib so i think I must “somewhat” to do this with BEGIN plus require&import, but absolutely don’t know how.


UPDATE: I’m already tried the basic things.

With require – my prg.pl program.

require 'mymods.pl';
$var = "hello";
croak "$var\n";

mymods.pl contain

use strict;
use feature 'say';
use Carp qw(carp croak cluck);
1;

DOES NOT WORKS. Got error:

$ 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.

with “use My”:

use My;
$var = "hello";
croak "$var\n";

my My.pm

package My;
use strict;
use feature 'say';
use Carp qw(carp croak cluck);
1;

DOES NOT WORKS either. Got the same error.


Any working idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:12:52+00:00Added an answer on May 23, 2026 at 11:12 am

    I’d go with this:

    package My::Common;
    use 5.14.0;
    use strict;
    use warnings;
    use autodie;
    use Carp qw(carp croak cluck);
    
    sub import {
        my $caller = caller;
        feature->import(':5.14');
        # feature->import('say');
        strict->import;
        warnings->import;
        ## autodie->import; # <-- Won't affect the caller side - see my edit.
        {
            no strict 'refs';
            for my $method (qw/carp croak cluck/) {
                *{"$caller\::$method"} = __PACKAGE__->can($method);
            }
        }
    }
    
    1;
    

    Please correct me if I’m wrong, or there’s a better way.


    EDIT:

    Sorry, I was wrong in using autodie->import…

    This one should work, but it assumes that you always call My::Common from the main package:

    package My::Common;
    # ...
    sub import {
        # ...
        strict->import;
        warnings->import;
        {
            package main;
            autodie->import;
        }
        # ...
    }
    

    So, of course, it’s much safer and simpler to add a use autodie; to each script:

    use My::Common;
    use autodie;
    # ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use some basic struct in C like the following: struct p
I want to use some features of python like as Tuples and Sets in
I want to use some packages (i.e., IPython or zdaemon ), butI am doing
i want use some data from a website with web service. i have a
I want to use some Python libraries to replace MATLAB. How could I import
I want to use some thing unique for a licensing system. i decided to
I want to use some NSAssert stuff and other things to enable better debugging
I want to use some kind of trigger to change a button in my
Hi have some forms that I want to use some basic php validation (regular
I m creating a game, in that i want to use some animation, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.