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

  • Home
  • SEARCH
  • 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 8324899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:14:56+00:00 2026-06-09T00:14:56+00:00

Apologies if this question isn’t appropriate for StackOverflow. I suspect the answer is largely

  • 0

Apologies if this question isn’t appropriate for StackOverflow. I suspect the answer is largely a matter of opinion (unless one of the style guides has a recommendation).

I have code that looks something like this

use File::Temp;

sub foo {
    ...
}
sub bar {
    ...
}
sub baz {
    my $fh = tempfile();
    ...
}

baz is the only subroutine that uses File::Temp, and I’m not using AutoLoader. Is it reasonable to put the use declaration inside baz, or should I leave it at the top of my script?

  • 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-06-09T00:14:58+00:00Added an answer on June 9, 2026 at 12:14 am

    Since (as chepner said), there is no difference technically, it really is a matter of style.

    The pros of putting then all on top:

    • Clear at first glance what all the direct module dependencies are

    • Easier to maintain – if you need to move around code using the library, you don’t need to remember to move the library.

      Please note that the same exact logic also applies to variable declarations, but in that case, the scoping concerns severely trump the “remember to move the declaration” concerns and therefore you should declare variables in the innermost possible scope as close to where they are used as possible.

    • For esoteric cases where your own code contains complicated logic in BEGIN{} blocks that depends on all the libraries being loaded (e.g., call a specifically named method from ALL loaded libraries – which I have done) – you will have a bug if some library’s use call is AFTER that BEGIN{} block

    The cons of putting them all on top:

    • One can possibly argue that this makes the code less readable since you need to seek out to the start of file to see what you imported from the module. Frankly, I don’t believe that but I have heard it expressed and it has at least some merit.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This isn't a question that has a black/white yes/no answer, this is more a
Apologies up front, because this isn't a question but a solution - but it
Apologies for the recursive nature of this question but the chosen answer to a
Apologies if this question is a bit obscure, I've been banging my head against
Apologies for this question but I am a bit of a noob with Delphi.
My apologies if this question has been asked before. I can see there are
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
Apologies if I missed this question already, but I searched and couldn't find it.
(Apologies for the title of this question - I wasn't overly sure how to
My apologies if you think this question is supposed to be on the Math

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.