Perl: recipe_5.2.pl PDF Print E-mail
Wednesday, 23 September 2009 21:12
#!/usr/bin/perl
#
if( $#ARGV < 0 or $#ARGV > 1 ) {
die "need just one argument: the file name";
}

$file=$ARGV[0];
open OUTFILE, ">$file" or
die "Could not create $file for writing";

# this many kilobytes will be multiplied by 1024. So a value of 1024 here
# produces 1024 * 1024 bytes of data (1 megabyte)
$KILOBYTES=1024;

for( $i = 0; $i<1024; $i++ ) {
# random char between "space" and 0x1F, which is the top of the
# ASCII printable range
my $char = int(rand(95));
$char = chr($char+32);

# print 1023 of them, and then a newline.
print OUTFILE $char x 1023 . "\n";
}

close OUTFILE;
Last Updated on Wednesday, 23 September 2009 21:15