in reply to Filling a File with While

It seems that File::System::Object returns the size that file occupies on disk, which is always a multiple of the block size.

If you don't want that, simple use -s:

while (-s $filename < $size) { print $fh "Some Something "; }

Or maybe you have problems with buffering, try to turn on autoflush: $| = 1.

Replies are listed 'Best First'.
Re^2: Filling a File with While
by koaps (Novice) on Nov 05, 2008 at 23:23 UTC
    I do want to know the size of the file on disk, how can I create a 1 gig file using the File::System::Object? I can see the blksize and blocks, so should I being doing something more like this:

    while ($v->get_property('block') < $bcount) { print $fh "Some Something "; }

    Where $bcount is the number of blocks I need to make up a 1 gig file? roughly 262,144 blocks right?

    Does the $fh have to be closed before I check the block size?

    while ($v->get_property('block') < $bcount) { $fh = $v->open('w'); print $fh "Some Something "; close $fh; }