Why are you using use integer? I think that is the source of most of your problems.

Without that, Perl will transparently convert your integers to reals if they get bigger than 2**32. Using reals, Perl can happily handle integer values upto 2**53 with no loss of accuracy. This equates to 9,007,199,254,740,992 which is 8 petabytes or ~ 8 million Gigabytes.

So unless you are expecting to be using drives greater than that, forget use integer and all the stuff about "loosing accuracy" and just let Perl take care of it.

Some code to demonstrate:

#! perl -slw use strict; use Win32::DirSize; use Data::Dumper; dir_size( 'p:\\', my $info ); print Dumper $info; ## As a string print $info->{DirSize}; ## Same field as an integer print 0+$info->{DirSize}; ## Same value by combining the high and low parts into a float printf "%.f\n", ( $info->{HighSize} * 2**32 ) + $info->{LowSize}; my $dirsize = $info->{DirSize}; if( $dirsize < 2**10 ) { printf "%d bytes\n",$dirsize } elsif( $dirsize < 2**20 ) { printf "%.2f KB\n", $dirsize / 2**10 } elsif( $dirsize < 2**30 ) { printf "%.2f MB\n", $dirsize / 2**20 } elsif( $dirsize < 2**40 ) { printf "%.2f GB\n", $dirsize / 2**30 } elsif( $dirsize < 2**50 ) { printf "%.2f TB\n", $dirsize / 2**40 } elsif( $dirsize < 2**60 ) { printf "%.2f PB\n", $dirsize / 2**50 } else{ print "This number is probably wrong: $dirsize"; } __END__ [ 1:15:03.82] P:\test>DirSize.pl $VAR1 = { 'DirCount' => 3866, 'LowSizeOnDisk' => 140623872, 'HighSizeOnDisk' => 4, 'FileCount' => 67685, 'DirSizeOnDisk' => '17320493056', 'DirSize' => '46480798709', 'LowSize' => 3531125749, 'Errors' => [], 'HighSize' => 10 }; 46480798709 46480798709 46480798709 43.29 GB

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re: Win32::DirSize and GB amount of data by BrowserUk
in thread Win32::DirSize and GB amount of data by Real Perl

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.