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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:12:33+00:00 2026-05-16T11:12:33+00:00

I have a perl script that will perform some operations on directories, and I

  • 0

I have a perl script that will perform some operations on directories, and I only wait it to run on directories for which the current user(e.g. the user executing the script) has ownership.

I’ve tried the following:

...
my $user = getlogin();
opendir(HANDLE, $path) or die ("No such directory: $path");
foreach my $directory (readdir HANDLE)
{
    opendir(WORKING_DIR_HANDLE, "$path/$directory") or die ("!!!!!!!");
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat(WORKING_DIR_HANDLE);
    my $owner = getpwuid($uid);
    if( $owner eq $user )
    {
      ...
    }
}
...

The code works for the most part. However, the call to stat() returns undefined values. According to the perl docs, I think I am making the stat() call correctly:

* stat FILEHANDLE
* stat EXPR
* stat DIRHANDLE
* stat

 Returns a 13-element list giving the status info for a file, either the file opened via
 FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is omitted, it stats $_ . Returns the 
 empty list if stat fails. Typically used as follows:

I have also tried just pasing it an EXPR using the file name, and I get the same results. Am I just missing something obvious? Or is there another way to do this? I would prefer a solution that does not require installing third-party perl modules.

  • 1 1 Answer
  • 1 View
  • 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-16T11:12:33+00:00Added an answer on May 16, 2026 at 11:12 am

    stat returns an empty list on failure, which sets all those variables to undef. Add or die $! after the call to find out why it failed:

    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
       = stat(WORKING_DIR_HANDLE) or die $!;
    

    Once you know why it failed, you may be able to figure out how to fix it. If not, then add the error message to your question.

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

Sidebar

Related Questions

I have a Perl script that will execute three applications. All of it have
I have a Perl script that takes user input and creates another script that
I have a perl script (or any executable) E which will take a file
I have a Perl script that sets up variables near the top for directories
I have a Perl script that contains this code snippet, which calls the system
I have a Perl script that outputs some colored text under bash. For example,
I have a Perl script that uses WWW::Mechanize to read from a file and
I have a Perl script that takes text values from a MySQL table and
I have a Perl script that launches 2 threads,one for each processor. I need
I have a Perl script that requires a couple of plugins, for istance nmap.

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.