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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:13:24+00:00 2026-05-15T10:13:24+00:00

Can someone advise on why I get errors opening the file in the code

  • 0

Can someone advise on why I get errors opening the file in the code below. The errors start about half way through the 9th iteration of 25 threads, and are “Too many open files” errors. The error only happens when running in threads, and only when the DBI connect/disconnect are used. This shouldn’t affect the open file count at all should it?
I’m fairly new to Perl so not sure if I’ve done something weird. This is on Perl 5.8.8. on Solaris 10.

use threads ();
use DBI;
use DBD::Oracle;

my $thrds=25;
my $iter=10;
my @threads;

for (my $j=0; $j<$iter; $j++) {
    &start($j);
}

sub start {
    my $k=$_[0];
    for (my $i=0; $i<$thrds; $i++) {
        $threads[$i] = threads->new(\&RunThread,$k, $i);
    }
    for (my $i=0; $i<$thrds; $i++) { $threads[$i]->join; }
}

sub RunThread {
    my $dbh = DBI->connect("dbi:Oracle:lnrmsd9.world", "rms_reader", "rms_reader") or die "failed connect";
    my ($x, $y)=@_;
    open (my $fh, ">/tmp/da") or die "failed $! at iter $x thread $y";
    close ($fh);
    $dbh->disconnect;
}
  • 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-15T10:13:24+00:00Added an answer on May 15, 2026 at 10:13 am

    You need to use:

    use warnings;
    use strict;
    

    These would tell you that you’re using global variables $i and $j in the subroutine. Since you’ve got multiple threads accessing the variables, all hell breaks loose. Also, they’re all sharing a single FILE, too – another source of trouble. And did you realize you had both a scalar ‘$threads’ and an array ‘@threads’?

    With threads, global variables are … well, if not exactly the enemy, extremely problematic.

    Avoid the FILE handle form of open; use my much more liberally.

    And you don’t need to say ‘use DBD::Oracle;’ ever. You might sometimes need to use the variant:

    use DBD::Oracle qw( :ora_types );
    

    to gain access to Oracle-specific data types.


    Untested revision:

    use strict;
    use warnings;
    use threads ();
    use DBI;
    use DBD::Oracle;
    
    my $threads=25;
    my $iter=10;
    
    for ($j = 0; $j < $iter; $j++) {
        &start($j);
    }
    
    sub start {
        my($j) = @_;
        my(@threads);
        for (my $i = 0; $i < $threads; $i++) {
            $threads[$i] = threads->new(\&RunThread,$j, $i);
        }
        for ($i=0; $i < $threads; $i++) { $threads[$i]->join; }
    }
    
    sub RunThread {
        my $dbh = DBI->connect("dbi:Oracle:ora", "user", "pass") or die "failed connect";
        my($j, $i) = @_;
        open(my $fh, ">/tmp/da") or die "failed $! at iter $j thread $i";
        close $fh;
        $dbh->disconnect;
    }
    

    One thing I didn’t understand – why shouldn’t I use use DBD::Oracle;?

    If you look at the ‘perldoc DBD::Oracle’, you will see the Synopsis:

    use DBI;
    
    $dbh = DBI->connect("dbi:Oracle:$dbname", $user, $passwd);
    

    So, the primary documentation for the DBD::Oracle module shows that you do not use it directly.

    There is no harm done in using it; there is no need to use it. The DBI module automatically loads the driver implied by the connection string in the call to DBI->connect(). By writing use DBD::Oracle;, you save the DBI from having to actually do the loading (it is already done). I suppose you also get Perl to verify that the module is available to be loaded with the use clause.

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

Sidebar

Ask A Question

Stats

  • Questions 443k
  • Answers 443k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to use the function pointer type as the… May 15, 2026 at 6:14 pm
  • Editorial Team
    Editorial Team added an answer Try adding validationEvent:false (docs). May 15, 2026 at 6:14 pm
  • Editorial Team
    Editorial Team added an answer Most of the other answers refer to using various hashing… May 15, 2026 at 6:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.