#! /usr/bin/perl -w use strict; # use all the modules I'm using in the main script, just in case use DBI; use File::Basename qw/basename/; use File::Path qw/mkpath/; use Getopt::Mixed; use IO::File; use IO::Tee; my $max = shift || 3; BEGIN { my @now; sub work_name { @now = localtime unless @now; sprintf( '/var/log/test/%02d%02d%02d.log', sub{ @_[reverse 0..2] }->(@now) ) } } my $logger = do { my $logfile = work_name(); my $fd = new IO::File( "> $logfile" ) or die "Could not open $logfile for output: $!\n"; new IO::Tee(\*STDOUT, $fd ); }; END { $logger and $logger->flush and $logger->close } for( 1..$max ) { my $letter = ('a'..'z')[rand 26]; my $lines = 1 + int(rand(10)); my $cols = 1 + int(rand(72)); $logger->print( "$_ ", (($letter x $cols) . "\n") x $lines ); } $logger->print("--end--");