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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:56:38+00:00 2026-05-20T05:56:38+00:00

Possible Duplicate: error of importing DBI in Perl I have a problem when I

  • 0

Possible Duplicate:
error of importing DBI in Perl

I have a problem when I use the DBI module in another module, script.pm.

package CC;


use DBI;
use strict; 
use Alias;


my $dbFile = 'XXXXXXXX.db';

my $db = DBI->connect("dbi:SQLite:$dbFile","","",
    {RaiseError =>1, AutoCommit => 1})or "Unable to connect:  $DBI::errstr\n";


use Alias qw(attr);
our ($CURRENTOFFSET,@LANGUAGE);

sub new {
    my $that = shift;
    my $class = ref($that)|| $that;
    my $self = {
        CURRENTOFFSET=> undef,
        LANGUAGE => []  
    };
    bless($self, $class);
    return $self;
}
  • 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-20T05:56:39+00:00Added an answer on May 20, 2026 at 5:56 am

    Substantive

    Conventionally, a package XYZ is kept in a file XYZ.pm; Perl won’t find your package otherwise. Thus, your file should be CC.pm rather than script.pm.

    Note that a package Organization::Team::Purpose is kept in a file Purpose.pm, but the file is kept in a sub-directory Organization/Team and the base directory holding Organization has to be found by Perl (using -I/some/where if Organization is a sub-directory of the directory /some/where, for example; if it is a sub-directory of the current directory, it will be found anyway).

    You should probably review the or clause after your connection attempt. Normally, you do a die or croak there. You simply evaluate a string, which is not very useful.

    You have:

    my $db = DBI->connect("dbi:SQLite:$dbFile","","",
        {RaiseError =>1, AutoCommit => 1})or "Unable to connect:  $DBI::errstr\n";
    

    You should consider what to do, but one technique is:

    use Carp;
    my $db = DBI->connect("dbi:SQLite:$dbFile", "", "",
                          { RaiseError => 1, AutoCommit => 1 })
             or croak "Unable to connect: $DBI::errstr\n";
    

    The downside of that is that this is going into a module, and it isn’t necessarily a good idea to croak in the BEGIN code of a module (and I’m making an assumption that the code is executed as the module is loaded). You might need to store the undef database handle and protect other methods from using it. You might be better off deferring the ‘connect to database’ operation until the constructor new is used (possibly for the first time). It is at least legitimate to raise errors at that point.

    As the answer by DVK noted (before I wrote my answer), modules should end with 1; to indicate successful loading. Maybe you can exploit that to report an error on failure to load – the final condition might be ‘defined $db ? 0 : 1;‘ (or even just ‘defined $db;‘), but it would be crucial to generate an error message somehow to explain the problem.

    Trivia

    You should be ruthlessly consistent in the spacing around operators, too. Your example includes:

    {RaiseError =>1, AutoCommit => 1}
    my $class = ref($that)|| $that;
    CURRENTOFFSET=> undef,
    

    which would be better written as:

    {RaiseError => 1, AutoCommit => 1}
    my $class = ref($that) || $that;
    CURRENTOFFSET => undef,
    

    The first might benefit from a little more space:

    { RaiseError => 1, AutoCommit => 1 }
    

    It doesn’t directly affect the operation of the code. It does make it a little less easy to read. Learning to be consistent is an important part of learning to program.

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

Sidebar

Related Questions

Possible Duplicate: Error loading Active Record gem with sinatra app using RVM I have
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Foursquare API for venue user image error I first noticed this problem
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Why does gcc have “â” in all its error messages? New to
Possible Duplicate: error when uploading string with special characters I have a string say
Possible Duplicate: Error handling in C code What return value should you use for
Possible Duplicate: Fatal error: Cannot use object of type stdClass as array in Please

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.