Subject: | Returns false on failure, not undef |
Documentation says:
RETURN VALUES
Both functions return undef if there is an error.
I find this is not the case.
$ perlsh
eval: use Term::Size;
undef
eval: pipe( my $rd, my $wr ); [ Term::Size::chars $rd ]
[ '' ]
This comes from the use of XSRETURN_NO in
PPCODE:
if (ioctl(fileno(f), TIOCGWINSZ, &w) == -1)
XSRETURN_NO;
If instead you use XSRETURN(0) then it will return undef in scalar
context, or an empty list in list context. This makes it easy to detect
a failure:
my ( $cols, $lines ) = chars( $fh ) or die "Cannot get size - $!";
--
Paul Evans