#
# 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";
}