(You don't need to tell me that this is a very old version of Perl, I know, I agree, and there isn't much I can do about it.)perl -v This is perl, v5.8.6 built for VMS_IA64 (with 2 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall (...)
I have a small program trying to list the files on a disk partitioned by age and by size, with some typical code like this:
My problem is that for a dozen or so very large files, the $size variable takes a negative value. For example, in one specific case, I got the following value: -426648576. Note that the stat function returns the same negative value in field # 7 (size in bytes) and an empty string for field # 12 (size in blocks).for my $entry (@files) { # @files contains the files I want to lo +ok at next if -z $entry; my $size = -s $entry; # more code
Obviously, the stat function and the -s file test operator are suffering from integer overflow.
Also note that POSIX's stat does not help and gives the same result.
I have found a work around: using a VMS system command within backticks to get the size blocks from VMS and then proceed with the necessary extraction and conversion. The specific file example above gives me a size of 7,555,310 blocks, which corresponds to about 3.8 GB (a VMS block is equal to 512 bytes). So, I am OK, my program does what I want with this work around.
I wonder, however, if there isn't a better way to get the size in pure Perl (i.e. without running a VMS system command within backticks), without having this integer overflow problem. Any idea?
In reply to Integer overflow in -s or file stat results by Laurent_R
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |