?
Solved

File::stat returns undef for anything that isn't . or ..?

Posted on 2003-03-24
2
Medium Priority
?
324 Views
Last Modified: 2010-03-05

Hello, all ...

I'm new to Perl ... as evidenced by my being clueless as to why this script does not do what I want:


#!/usr/bin/perl

opendir( ACE_BUILD_DIR, "//Users//jmzorko//ace_daily_build" );

@files = readdir( ACE_BUILD_DIR );

print "@files\n\n\n\n\n";

use File::stat;

foreach $thisfile (@files)
{
    $st = stat($thisfile);

    if ( $st != undef )        // ?????
    {
        $age = $st->mtime;

        print "$thisfile : $age - $^T\n";

        if ( $st->mtime - $^T == 0 )
        {
            print "$thisfile  today\n";
        }
    }
}

Basically, the stat() is fine for the . and .. elements in the file array, but as soon as it gets to a file with a name other than . or .., stat() returns undef.  I've tried this on Mac OSX 10.2.4 (Perl 5.8.1) as well as Red Hat Linux (2.4 kernel, Perl 5.8.0).  These files have permissions of 644 ... and i'm the owner, so i've no idea why stat() won't stat them.  Can someone who knows Perl help?

Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.mp3.com/fallingyou

0
Comment
Question by:jmzorko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 8200383
#!/usr/bin/perl

$dir="//Users//jmzorko//ace_daily_build";
opendir( ACE_BUILD_DIR, $dir ) or die "Can't open $dir $!";

@files = readdir( ACE_BUILD_DIR );

print "@files\n\n\n\n\n";

use File::stat;

foreach $thisfile ( @files ){
   $st = stat("$dir/$thisfile");

   if ( $st ){
       $age = $st->mtime;

       print "$thisfile : $age - $^T\n";

       if ( $st->mtime - $^T == 0 )
       {
           print "$thisfile  today\n";
       }
   }
}
0
 

Author Comment

by:jmzorko
ID: 8204108

Ozo,

Thanks -- silly me misunderstood the opendir command, evidently :-)

Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.mp3.com/fallingyou



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question