in reply to STDIN and STDOUT as a single filehandle?

perltie

update: Here is a start

package ReadOneWriteOtherone; use strict; use warnings; sub TIEHANDLE { my( $self, $in, $out ) = @_; $self = bless { in => $in, out => $out}, $self; return $self; } sub PRINT { my $self = shift; $self = $self->{out}; print $self @_; } sub READLINE { my $self = shift; $self = $self->{in}; readline $self; } sub CLOSE { my $self = shift; close $self->{in}; close $self->{out}; } 1; package main; unless( caller ){ tie *BLOG => ReadOneWriteOtherone => \*STDIN, \*STDOUT or die "Cou +ldn't tie BLOG : $!"; print tied(*BLOG),$/; print tied(*BLOG)->{in},$/; print tied(*BLOG)->{out},$/; print "Enter some input buddy and hit enter : $/"; print BLOG "You entered: ", scalar <BLOG>; } __END__ $$ perl ReadOneWriteOtherone.pm ReadOneWriteOtherone=HASH(0x1abf1a4) GLOB(0x1ab7f34) GLOB(0x1ab5054) Enter some input buddy and hit enter : Hi there You entered: Hi there

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: STDIN and STDOUT as a single filehandle?
by scottb (Scribe) on May 31, 2004 at 19:44 UTC
    Okay I get the gist of that, but as it was with the 'ReadOneWriteOther.pm' I was getting an error:
    Can't locate object method "FILENO" via package "ReadOneWriteOther" at /usr/lib/perl5/site_perl/5.8.0/Net/Telnet.pm line 560.
    So I figured I had to just add a 'sub FILENO' in and choose to return either 'fileno $self->{in}' or out, but neither worked. Both get the error:
    stat() on unopened filehandle TERM at /usr/lib/perl5/site_perl/5.8.0/Net/Telnet.pm line 578.
    ... and then when I open the shell with Net::SSH::Perl, it uses STDIN and STDOUT on the terminal as before. So I get the idea, but I'm stuck again. Any further help would be appreciated.

    Thanks,
    Scott

      Just add AUTOLOAD to handle not implemented methods:
      sub AUTOLOAD {}
      Take a look in perltie to implement all the other methods if you really want to make a full IO redirection through tie.

      Here's a list of the other methods:

      sub PRINTF {} sub READ {} sub READLINE {} sub GETC {} sub WRITE {} sub FILENO {} sub STORE {} sub FETCH {} sub CLOSE {} sub DESTROY {}

      Graciliano M. P.
      "Creativity is the expression of the liberty".