Laurie Vien [EMAIL PROTECTED] wrote:
> I'm trying to just determine the size of a file before
> I decide whether to process it. In the following code,
> $size always comes out null:
>
> foreach $xFile (@xFileList) {
> $size = (stat ($xFile))[7];
> if ($size gt 0) {
> print " Found file $xFile with size $size, so WILL push it
...\n";
> } else {
> print " Found file $xFile with size $size, so will NOT push it
...\n";
> };
>
> I also tried $size = (-s _) instead of using "stat",
> but got the same result--$size comes out null. What
> am I doing wrong?
You code is valid, but it really depends on the contents
of @xFileList . Try adding:
print " xFile='$xFile'\n";
just after the "foreach" line. Maybe you have relative
pathnames, but are in the wrong directory. The real issue
is likely that "stat ($xFile)" is returning undef because
the file does not exist. To verify this theory, add this
after the "print" I show above:
my @stat = stat( $xFile );
die "*** Error: cannot stat( $xFile )\n" unless @stat;
You are running with
use strict;
use warnings;
turned on right? This would help you catch those undef errors.
--
Mike Arms
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs