#! perl -w use strict; $| = 1; print "$0 | start | " . localtime() . "\n"; print STDOUT "This is STDOUT\n"; print "Now ask for STDIN: "; my $input = ; chomp($input); print "Input : " . $input . "\n"; print "Now let's mess with things...\n"; my $logfile = "./logfile.log"; open( STDOUT_TOO, ">&STDOUT" ) or die "Cannot dup STDOUT handle to STDOUT_TOO: $!"; open( LOGFILE, ">$logfile" ) or die "Cannot open $logfile for output: $!"; tie *STDOUT, 'MyMultiplex', \*STDOUT_TOO, \*LOGFILE; print "And let's see the effects...\n"; print STDOUT "This is STDOUT\n"; print "Now ask for STDIN: "; $input = ; chomp($input); print "Input : " . $input . "\n"; print "$0 | end | " . localtime() . "\n"; package MyMultiplex; sub TIEHANDLE { my $obj = shift; bless [ @_ ], $obj; } sub PRINT { my $self = shift; print $_ $_[0] for @$self; } #### H:\Developer\deploysystem\src>perl scratch.pl scratch.pl | start | Wed Jun 30 12:13:45 2004 This is STDOUT Now ask for STDIN: this is 5.6 Input : this is 5.6 Now let's mess with things... 'mess with things' printed out of sequence And let's see the effects... This is STDOUT Now ask for STDIN: Input : 'mess with things' printed out of sequence scratch.pl | end | Wed Jun 30 12:14:06 2004 #### H:\Developer\deploysystem\src>perl scratch.pl scratch.pl | start | Wed Jun 30 12:15:07 2004 This is STDOUT Now ask for STDIN: this is 5.8 Input : this is 5.8 Now let's mess with things... And let's see the effects... This is STDOUT Now ask for STDIN: it works on my machine! Input : it works on my machine! scratch.pl | end | Wed Jun 30 12:15:18 2004