kenth has asked for the wisdom of the Perl Monks concerning the following question:

To do some alert testing I needed to create a very large file on windows, so I wrote a little perl script to do it. This script works fine on my desktop with ActivePerl 5.8.8. I put it on the servers I need to test with Perl 5.6.1 and it doesn't work at all. Can anyone suggest why?
# Script create_big_file.pl # # Generates a file 10gb in size. Use -s to change the size. # use Getopt::Std; my $usage = <<EOT; Usage: $0 [-h] [-f file] [-s size] -h This help screen. -f file The file to create. -s size Size of the file to create in GB. Example: create_big_file.bat -s 26 -f 26gb.dat EOT warn($usage), exit(0) if !getopts('hf:s:',\%OPT) or $OPT{'h'}; $filesize = 10000000000; if ($OPT{'s'}) { $filesize = $OPT{'s'} * 1000000000 ; } $filename = "oat_bigfile_1.dat"; if ( $OPT{'f'}) { $filename = $OPT{'f'}; } $size = $filesize -1; print STDOUT "Creating $filename of $filesize bytes.\n"; open(BIGFILE, "+>", "$filename") || die ("Could not create $filename.\ +n"); binmode BIGFILE; die("Could not extend $filename to $filesize bytes.\n") unless seek BI +GFILE, $size, 0; print BIGFILE "\0"; seek BIGFILE, 0, 0; close BIGFILE;

Replies are listed 'Best First'.
Re: Pre-extend a file on Windows
by BrowserUk (Patriarch) on Jul 13, 2007 at 20:03 UTC
      Thanks for the contig.exe suggestion. That does what I need. I looked at the perl they have installed on the servers and it does not have largefile support compiled in so that explains the problem. Thanks
Re: Pre-extend a file on Windows
by jwkrahn (Abbot) on Jul 13, 2007 at 19:32 UTC
    Can't you just use truncate to create a large file?
    $ touch myfile $ ls -l myfile -rw-r--r-- 1 john john 0 2007-07-13 12:30 myfile $ perl -e'truncate "myfile", 200_000_000' $ ls -l myfile -rw-r--r-- 1 john john 200000000 2007-07-13 12:31 myfile
Re: Pre-extend a file on Windows
by toolic (Bishop) on Jul 13, 2007 at 19:39 UTC
    I tried this on my Unix solaris system which has perl 5.6.1, and the cutoff seems to be somewhere between 2G and 3G. I could create a 2G file, but not a 3G file.

    Could it be an OS limitation, rather than a Perl version issue?

Re: Pre-extend a file on Windows
by thezip (Vicar) on Jul 13, 2007 at 19:51 UTC
    kenth,

    Did you compile your script in the 5.6 environment? This might have provided an insight into your problem.

    (Where do I get such stories? It was first implemented in perl 5.6. I go away now...)

    The three argument form of open did not exist in perl 5.6.

    You'll need to change the line to read:
    open(BIGFILE, "+>$filename") || die ("Could not create $filename.\n");

    Also, you'll be using strictures and warnings, right?


    Where do you want *them* to go today?
Re: Pre-extend a file on Windows
by andreas1234567 (Vicar) on Jul 13, 2007 at 20:03 UTC
    What file systems are in use?
    --
    print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})