in reply to IO::Select woes
Hi again Monks,
I have duplicated the issue. I just simply wrapped the STDIN check in a function. When I run this very simple script through the pipe, can_read() doesn't detect anything on STDIN. When I run it through the debugger, it works fine. When I uncomment the print statement in checkPipe, it triggers something and works fine without the debugger! What am I possibly doing wrong here? I am losing my sanity! Could it possibly be the timeout as Bliako stated? I tried changing it, but it doesn't seem to change anything.
# # TEST RUN # # # perl test2.pl | perl test2.pl ## PRINTS NOTHING !!!
# perl test2.pl | perl -d test2.pl reading from pipe data .------------------------------. | Basket | +----+-----------------+-------+ | Id | Name | Price | +----+-----------------+-------+ | 1 | Dummy product 1 | 24.4 | | 2 | Dummy product 2 | 21.2 | | 3 | Dummy product 3 | 12.3 | +----+-----------------+-------+ | | Total | 57.9 | '----+-----------------+-------'
## test2.pl # #!/usr/bin/perl5.26.1 use strict; use Text::ASCIITable; use IO::Select; use strict; use warnings; $|=1; checkPipe(); sub checkPipe { #print "checking pipe\n"; #<==== UNCOMMENT IT WORKS!! my $s = IO::Select->new(); $s->add(\*STDIN); if ($s->can_read(.5)) { print STDOUT "reading from pipe data\n"; dumpTable(); } } sub dumpTable { my $t = Text::ASCIITable->new({ headingText => 'Basket' }); $t->setCols('Id','Name','Price'); $t->addRow(1,'Dummy product 1',24.4); $t->addRow(2,'Dummy product 2',21.2); $t->addRow(3,'Dummy product 3',12.3); $t->addRowLine(); $t->addRow('','Total',57.9); print STDOUT $t ."\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: IO::Select woes
by hv (Prior) on May 05, 2023 at 17:52 UTC | |
by Anonymous Monk on May 05, 2023 at 18:22 UTC | |
Re^2: IO::Select woes
by haj (Vicar) on May 05, 2023 at 17:54 UTC |