CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
File::stat returns undef only some times?! :-(

 



ThePerlJunkie
New User


Sep 26, 2011, 5:26 PM

Post #1 of 5 (3590 views)
File::stat returns undef only some times?! :-( Can't Post

Anyone seen any behavior with File::stat (or stat or lstat) returning an undefined value used in a File::Find routine? I'm getting consistently inconsistent results. :-) Meaning, I can't seem to stat certain files and they are the same files -- seemingly. Can't find a thing wrong with the files -- they are regular text files, most of them. But sometimes a file will come back undefined. Beats the mess out of me. Can't seem to find a lot on this out there, so I thought I would ask. I'm displaying to stdout all the files File::Find returns with $File::Find::name, so it's traversing whatever tree I give it, but... I get undefineds here and there. I own the files, they are 644... They are not locked... No explanation.

And what's the big idea of someone stealing my screen name here at TPA?!! :-) (Just kidding. Nothing that a simple article prefix didn't fix... :-))

-pj
--
Perl Junkie
Custom OO Perl, Ruby code and layered product installs and customizations (WP, JM!, MT, etc.) on demand


FishMonger
Veteran / Moderator

Sep 26, 2011, 6:48 PM

Post #2 of 5 (3586 views)
Re: [ThePerlJunkie] File::stat returns undef only some times?! :-( [In reply to] Can't Post

Can you post your code?


ThePerlJunkie
New User


Sep 26, 2011, 7:05 PM

Post #3 of 5 (3584 views)
Re: [FishMonger] File::stat returns undef only some times?! :-( [In reply to] Can't Post

Aside from the OO app references, I think the gist is pretty easy here. You can see where I have to check undefined because of well... what I said. This isn't complicated.


Code
use File::Find; 
use Fcntl qw( :mode );
:
:
somewhere down south of here in a sub far, far
away...
:
:

sub do_it {
find( sub {
my $filespec = $File::Find::name;
my $fstat = stat( $filespec );
unless ($fstat) {
$app->__verbose( "Filespec: $filespec (couldn't stat?)" );
return;
}
return if S_ISDIR( $fstat->mode );
$app->__verbose(
"Filespec: $filespec " .
"Size: ${\ $fstat->size } " .
"Blocks: ${\ $fstat->blocks }"
);
unless ($fstat->size) {
$app->__verbose( "Purging: $filespec" );
unlink( $filespec )
unless $app->options->testOnly;
}
}, $app->options->sourcePath );
}


-pj
--
Perl Junkie
Custom OO Perl, Ruby code and layered product installs and customizations (WP, JM!, MT, etc.) on demand


ThePerlJunkie
New User


Sep 26, 2011, 7:08 PM

Post #4 of 5 (3583 views)
Re: [ThePerlJunkie] File::stat returns undef only some times?! :-( [In reply to] Can't Post

Pretend I remembered to add:


Code
use File::stat;


Or the $fstat refs aren't going to make any sense. :-)

-pj
--
Perl Junkie
Custom OO Perl, Ruby code and layered product installs and customizations (WP, JM!, MT, etc.) on demand


ThePerlJunkie
New User


Sep 26, 2011, 7:18 PM

Post #5 of 5 (3582 views)
Re: [ThePerlJunkie] File::stat returns undef only some times?! :-( [In reply to] Can't Post

OS right now is actually Mac OS X Snow Leopard. I'll move this over to SuSE Linux tomorrow and try it again. Could just be Snow Leopard for some reason. I forget I'm on the Mac sometimes, it's so seamless in just about everything I do. If this is the only issue I have with Mac OS X, I think I can live with it. As long as it works on Linux.

In fact, if I had been thinking, just for that fact alone, I might have refrained from posting. I have Linux windows open everywhere, but I'm running this against a Mac OS X file system. Still should work in my opinion.

An identical Ruby version works without a hitch which irritates me as well.

-pj
--
Perl Junkie
Custom OO Perl, Ruby code and layered product installs and customizations (WP, JM!, MT, etc.) on demand

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives