in reply to Problems using File::stat,Find under windows

Unfortunately, since I rarely (if ever) code Perl under Windows, I may not have an immediate advice to cure your problem. However, I still think you don't have to do the '-f' check inside your wanted subroutine. My thinking is that the file ($File::Find::name) should always exist, hence the reason it was found in the first place.

As to why you are getting the "Can't call method 'size' on an undefined value" error, it seems as if the stat() function fails to obtain file statistics due to reasons such as certain file attributes (hidden, archive, etc.)? If you are working on WindowsNT there also might be some conflicting group/user permissions at play.

To shield yourself from the error, you might consider adding this check:
.... if (my $file_stat = stat($File::Find::name)) { $wanted_count[$i] += $file_stat->size; } else { print "Failed to obtain stats on file '$File::Find::name'"; } return; .....


"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

Replies are listed 'Best First'.
Re: Re: Problems using File::stat,Find under windows
by demerphq (Chancellor) on Mar 22, 2002 at 13:45 UTC
    you don't have to do the '-f' check inside your wanted subroutine. My thinking is that the file ($File::Find::name) should always exist,

    While you are mostly corrct about the file existing (although on a multiuser system it might have been deleted in the meantime) youve got the meaning of the -f filetest wrong. It returns true if the item in question is a file. And File::Find will match directories as well as files. So the meaning of this test in this case is to eliminate any found dirs.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.