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 7494209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:22:45+00:00 2026-05-29T17:22:45+00:00

When should we use use and when require and when AUTOLOAD in perl ?

  • 0

When should we use “use” and when “require” and when “AUTOLOAD” in perl ? I need a thumb rule for this.

  • 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-29T17:22:47+00:00Added an answer on May 29, 2026 at 5:22 pm

    use is equivalent to BEGIN { require Module; Module->import( LIST ); }

    So, the main difference is that:

    • Use is used at compile time

    • Use automatically calls import subroutine (which can do anything but mostly used to export identifiers into caller’s namespace)

    • use dies if the module can not be loaded (missing/compile error)

    As such:

    • When you need to load modules dynamically (for example, determine which module to load based on command line arguments), use require.

    • In general, when you need to precisely control when a module is loaded, use require (use will load the module right after the preceding use or BEGIN block, at compile time).

    • When you need to somehow bypass calling module’s import() subroutine, use require

    • When you need to do something smart as far as handling load errors (missing module, module can’t compile), you can wrap the require into an eval { } statement, so the whole program doesn’t just die.

      You can simulate that with use but in rather in-elegant ways (trapping die signal in an early BEGIN block should work). But eval { require } is better.

    • In all OTHER cases, use use

    I didn’t cover AUTOLOAD as that’s a different beastie. Its usage is in cases when you want to intercpt calls to subroutines that you haven’t imported into your namespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In PHP: When should I use require vs. include ? When should I use
What should I use in the following statement? Include or required. if(a ==b){ require
MSDN says that you should use structs when you need lightweight objects. Are there
For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres
I want to know when I should use include or require and what's the
Should I use a password pattern like a-zA-Z0-9 and also require at least one
What GUI should use to run my JUnit tests, and how exactly do I
I've read I should use money , but in todays fast paced world maybe
Why sometimes I should use block and other times &block inside functions that accept
I know you should use POST whenever data will be modified on a public

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.