Dear Monks,
I have a script which dumps a table. When I pipe it to the same script, I use IO::Select and can_read() to check for input on STDOUT. My script works fine when I run it through the debugger, but sadly can_read() fails to detect anything when I don't. I tried writing a test script to see if I can reproduce the issue, but unfortunately the script works fine either way.Interestingly, when I put a print statement (marked HERE) in my script, the can_read() seems to work.
Any ideas ? Thank you very much for your time !!!
#!usr/bin/perl5.26.1 use strict; use IO::Select; use Text::ASCIITable; $|=1; 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"; ### print "checking pipe\n"; #<==== HERE my $s = IO::Select->new(); $s->add(\*STDIN); if ($s->can_read(.5)) { print STDOUT "reading from pipe data\n"; }
# # TEST RUN # # perl test.pl .------------------------------. | 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 | '----+-----------------+-------' # perl test.pl | perl test.pl .------------------------------. | 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 | '----+-----------------+-------' reading from pipe data
In reply to IO::Select woes by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |