Subject: | print() on invalid filehandle warns and returns success |
Date: | Wed, 03 Sep 2008 19:44:20 +0100 |
To: | bug-Text-CSV_XS [...] rt.cpan.org |
From: | ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker) |
Hi Merijn,
I noticed $csv->print($fh, \@fields) ignores errors that occur when
writing to $fh. Instead it gives a "Use of unititialized value in
subroutine" error and returns 1.
The below script demonstrates this when passed an unwritable file, such
as /dev/full, when it produces the following output:
Show quoted text
> $fh->print("testing"): No space left on device
> Use of uninitialized value in subroutine entry at /home/ilmari/tmp/csv-print.pl line 16.
> $csv->print($fh, ["testing"]): ok
Here's the script:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV_XS;
use IO::Handle;
my $csv = Text::CSV_XS->new;
open my $fh, '>', shift or die "open: $!\n";
$fh->autoflush(1);
print '$fh->print("testing"): ';
$fh->print("testing") and print "ok\n" or print "$!\n";
print '$csv->print($fh, ["testing"]): ';
$csv->print($fh, ["testing"]) and print "ok\n"
or print $csv->error_diag;
--
ilmari
"A disappointingly low fraction of the human race is,
at any given time, on fire." - Stig Sandbeck Mathisen