in reply to Re: Re: insert zero into binary files ?
in thread insert zero into binary files ?

Hi. I'm really not sure what you want to do, but my best guess is that you have a file, and you want to pad it to a certain length (2048000) with null (zero) bytes. If that's the case, try this totally untested code as a starting point:

my $desired_size = 2048000; my $current_size = -s $file; my $null_bytes = "\x00" x ($desired_size - $current_size); open OUT, ">>", $file or die; print OUT $null_bytes; close OUT;
--
3dan

Replies are listed 'Best First'.
Re: Re: Re: Re: insert zero into binary files ?
by hawtin (Prior) on Nov 06, 2003 at 18:41 UTC

    I would suggest a slight modification

    my $desired_size = 2048000; my $current_size = -s $file; my $null_bytes = "\x00" x ($desired_size - $current_size); open OUT, ">>", $file or die; binmode OUT; # <-- Some OSs need this print OUT $null_bytes; close OUT;