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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:29:36+00:00 2026-06-15T14:29:36+00:00

I have been messing with my code for an hour now and still no

  • 0

I have been messing with my code for an hour now and still no progress. Please hear me out:
This code worked early today, what it does is open the directory I give to the program, read it, and open each file in the directory and read them individually to perform some actions .

This is the way I do the file opening and reading:

use strict;
use warnings;
use File::Slurp;

my $dir = shift @ARGV;
opendir(DH, $dir) or die "Directory Open Error!";
my @filelist = grep !/^\.\.?$/, readdir(DH);

my $filename;
foreach $filename(@filelist){
open(FH, $filename) or die "File Open Error!";
my $readFile = read_file($filename);
#more code
}

So this works earlier and I have seen the code perform what I want it to do just fine, but when I ran the code on an other directory it returned

File Open Error! at program.pl line 15

After that I can’t make it work anymore, no matter how much I checked I still couldn’t figure out what went wrong.

Since the error is on the open() line, I first made sure correct file name was passed down, so I printed the list of file names after the directory was open, everything looks good.

Then I got rid of the open directory part, pass the file name manually:

$filename = shift @ARGV;
open(FH, $filename) or die "File Open Error!";
my $readFile = read_file($filename);

The program works, file opens just fine. So I got rid of the error message and return to the first code and this is what I saw:

read_file ‘somefile’ – sysopen: no such file or directory at
program.pl line 17

Line 17 is the line where I used read_file to read the content of a file, this happens after the file is open, I don’t understand what’s going on now. Again, this code was working earlier just fine and I really didn’t change anything except input and now it completely stop working

  • 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-15T14:29:37+00:00Added an answer on June 15, 2026 at 2:29 pm

    I think you need to filter-out directories and add $dir to filenames:

    use strict;
    use warnings;
    use File::Slurp;
    
    my $dir = shift @ARGV;
    opendir(DH, $dir) or die "Directory Open Error!";
    
    # here, use grep { !-d "$dir/$_"}
    my @filelist = grep {!-d "$dir/$_"} readdir(DH);
    
    my $filename;
    foreach $filename(@filelist){
      $filename = "$dir/$filename"; # also add dir
      print $filename, "\n";
      my $readFile = read_file($filename);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been messing with this code for quite some time, works in FF,
I have been messing around with writing some stored procedures in .NET code with
I have been tearing my hair out now for a week or so, it's
I have been messing around with HtmlUnit for a little bit and particularly this
I have been messing around with asp.net for awhile now and always have issues
I have been messing around with the Google's JavaScript code and I saw in
I have been messing with this for a while and I know it is
In the following code..I am getting no suitable driver..error: please help. I have been
I have been messing around with Leaks trying to find which function is not
I have been messing around with my meta descriptions, trying to make them more

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.