asr00 has asked for the wisdom of the Perl Monks concerning the following question:
i'm trying to test a module that should read data from file descriptor 3. I've write this code but i can't read from the file even if the files are flushed or autoflushed.
my expected output is:
aaaaaaaaaa
bbbbbbbbbb
bbbbbbbbbb
aaaaaaaaaa
bbbbbbbbbb
This is the code i'm working on
use strict; use warnings; use IO::Handle; use IO::File; my $ftmp = new IO::File "> test_eagi.tmp"; unless ( defined $ftmp) { die "Couldn't open (test_eagi.tmp)\n"; } if ( fileno($ftmp) == 3 ) { print "open file with fd 3\n"; } else { die "ERROR: file opened with fd : ".fileno($ftmp)."\n"; } $| = 1; $ftmp->autoflush(1); my $fh_in = new IO::Handle; my $fh_out = new IO::Handle; my $buff; my $blen = 10; $fh_in->fdopen(3,'w') || die "No se pudo abrir fh_in\n$!\n"; $fh_out->fdopen(3,'r') || die "No se pudo abrir fh_out\n$!\n"; #$fh_out->autoflush(1); $fh_in->autoflush(1); my $data_a = 'a'x10; my $data_b = 'b'x20; print "data a: ($data_a)\n"; print "data b: ($data_b)\n"; my $r = $fh_in->write($data_a,10); $fh_in->flush; $fh_out->read($buff,$blen); print "$buff\n"; $fh_in->write($data_b,20); $fh_out->read($buff,$blen); print "$buff\n"; $fh_in->write($data_a,10); $fh_out->read($buff,$blen); print "$buff\n"; $fh_in->write($data_b,20); $fh_out->read($buff,$blen); print "$buff\n"; $fh_out->read($buff,$blen); print "$buff\n"; $fh_out->close(); $fh_in->close(); $ftmp->close();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: testing interface
by almut (Canon) on Sep 25, 2009 at 19:38 UTC | |
by ikegami (Patriarch) on Sep 25, 2009 at 19:40 UTC | |
by asr00 (Initiate) on Sep 25, 2009 at 22:12 UTC | |
|
Re: testing interface
by ikegami (Patriarch) on Sep 25, 2009 at 19:26 UTC |