medellre has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use strict; $| = 1; print "$0 | start | " . localtime() . "\n"; print STDOUT "This is STDOUT\n"; print "Now ask for STDIN: "; my $input = <STDIN>; 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 STD +OUT_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 = <STDIN>; 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
edit: added another <readmore>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tied filehandle behaviour 5.6 vs 5.8
by jdalbec (Deacon) on Jul 02, 2004 at 02:44 UTC | |
by medellre (Initiate) on Jul 02, 2004 at 14:13 UTC |