Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-24
2
Medium Priority
?
330 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
2 Comments
 
LVL 85

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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

581 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