Dear fellow monks, I just ran into the following problem running a Perl program under VMS.
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 (...)
(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.)

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:

for my $entry (@files) { # @files contains the files I want to lo +ok at next if -z $entry; my $size = -s $entry; # more code
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).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.