Skip to content

Instantly share code, notes, and snippets.



Last active Aug 14, 2018
What would you like to do?
#!/usr/bin/env perl
use v5.10.1;
use strict;
use warnings;
use Fcntl ':DEFAULT';
# Usage:
# >/tmp/append; perl /tmp/append A $((2**12)) 4
# Will write 4 lines of 4095 "A"s and \n to /tmp/append
my ($file, $byte, $length, $times) = @ARGV;
my $str = ($byte x ($length - 1)) . "\n"; # -1 for \n
sysopen my $fh, $file, O_WRONLY|O_APPEND|O_CREAT, 0666 or die $!;
for my $n (1..$times) {
syswrite $fh, $str or die "Failed to write() the ${n}th time: $!";
close $fh or die $!;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment