my $iter = 0;
while( $iter++ < $MAX_ITERS ) {
do_stuff();
}
####
{
my $block_size = 207;
sub get_block_size { $block_size }
}
####
sub nuke_file {
my $file = shift;
my $cb = shift or die "No callback specified to nuke_file().\n";
die "$cb is not a coderef in nuke_file()\n" unless ref($cb) eq 'CODE';
my $file_size = (stat($file))[7];
my $bytes = 0;
my $block_size = get_block_size();
sysopen(BYEBYE, $file, O_WRONLY)
# be descriptive in your die string
or die "Could not open $file for output: $!\n";
while( $bytes < $file_size ) {
# deal with the tail end of the file correctly
my $len = $bytes + $block_size > $file_size
? $file_size - $bytes
: $block_size;
my $written = syswrite(BYEBYE, &$cb( $len ), $len, 0)
or die "Could not write $len bytes to $file: $!";
my $bytes += $written; # $err is a misleading name
}
close(BYEBYE);
}
####
sub all_ones {
0xff x $_[0];
}
nuke_file( $filename, \&all_ones );