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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:09:54+00:00 2026-06-06T22:09:54+00:00

I have a large script that has no database connection yet. I need one

  • 0

I have a large script that has no database connection yet. I need one for a tiny new feature. Is it safe to add a naked block to require DBI where I need it or do I need to import something?

# Lots of no-database code here...
my $obj;
{
  require DBI;
  my $dbh = DBI->connect('dsn');
  $obj = ModuleThatNeedsDBH->new(dbh => $dbh);
}
$obj->fancyStuff();
# More no-database code...

The block is to keep $dbh hidden from the rest of the program of course.

  • 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-06T22:10:02+00:00Added an answer on June 6, 2026 at 10:10 pm

    By default the DBI module imports nothing into the calling package so yes, in theory you could use require instead of use.

    But what are you hoping to gain from this? In this case use DBI is equivalent to BEGIN { require DBI }, and if you omit the BEGIN block you will be imposing the lengthy process of loading the package during run time which is undesirable.

    Note that you must also handle any failure to connect to the database.

    my $dbh = DBI->connect('dsn', 'user', 'pass')
                or die $DBI::errstr;
    

    although dying may be a little extreme in your case.

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

Sidebar

Related Questions

I have a database in production with one table that has grown extremely large
i have a sqlite3 database that has multiple (six) tables and i need it
I have a weekly script that moves data from our live database and puts
Essentially I have a large database of transactions and I am writing a script
I have a large PHP class that has a large variable/function declaration and I
I have a very large db that I am working with, and I need
i have this script It's a script that allow me to edit database tables
I have a very large script which contains a lot of php files, so
I have a fairly large script and am trying to find out, why $(document).on(
I have a very large script which is creating multiple views. In a number

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.