in reply to Munging STDIN and STDOUT into one handle
And then use it as:package TwoWayHandle; sub TIEHANDLE { my ($class, $in, $out) = @_; bless [ \$in, \$out ], $class; } sub PRINT { my $self = shift; local *FH = ${ $self->[1] }; print FH @_; } sub READLINE { my $self = shift; local *FH = ${ $self->[0] }; <FH>; } 1;
Not sure why, but I can't call chomp() at the same time I read from the filehandle.use TwoWayHandle; tie *ACDC, TwoWayHandle => ( *STDIN, *STDOUT, ) or die "can't tie *ACDC: $!"; print ACDC "What's your name? "; $name = <ACDC>; chomp $name; print ACDC "Hello, $name.\n";
|
|---|