The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/bin/perl -w

# Generates log files to test my "tail -f" implementation
# Usage : 
#  > gene.pl &                  # Generate the log files
#  > tail -f log &              # watch them

# This is not a good test program, because it is slower than the program
# itself (maybe because it writes into the files instead of reading
# from them). However, it's better than nothing.

# n is the number of log files to be created and changed continuously
# Increase it as you will. I have tried values up to 1000.
$n=10;

# The directory where the files are stored
$logdir = "$ENV{'HOME'}/temp/tail/log";

sub append($$)
{
    open OUT, ">>$logdir/$_[0]" 
	or print "cannot open $logdir/$_[0]\n";
    print OUT "$_[1]\n";
    close OUT;
}

$file="log";

$i=0;
while(++$i) {
    print "Step $i...\n";
    
    for $f(1 .. $n) {
	append "$file.$f", "Message $f-$i";

	# From time to time, add more than 1 line
	if(($f+$i)%10 == 0) {
	    for (1..5) {
		append "$file.$f", "Message $f-$i-$f";
	    }
	}
    }
    sleep 2;
}