Subject: | format_write and I/O operator write don't work |
Using perl's formatted output functions with a file handle such as IO::Lines does not work. When using the I/O operator write, a warning about writing to an unopened filehandle is output. When using the OO syntax, no errors or warnings are produced. In both cases, the output never makes it into the array.
Please see the attached code that reproduces the bug, and email me if you have any questions.
Distribution name and version: IO-stringy-2.110
Perl version: v5.8.6
OS: Cygwin 1.5.12
#!/usr/bin/perl
use Data::Dumper;
use IO::Lines;
use strict;
use warnings;
# Setup
my $foo = "Written";
format FOO =
@||||||||||||||||||
$foo
.
# Demonstrate code works with STDOUT
print STDOUT "Written using STDOUT:\n";
select(STDOUT);
print "Printed\n";
$~ = "FOO";
write;
print "OO syntax written:\n";
STDOUT->format_name( "FOO");
STDOUT->format_write;
# Fails with IO::Lines
print STDOUT "Written using IO::Lines:\n";
my @foo;
my $fh = new IO::Lines \@foo;
select($fh);
print "Printed\n";
$~ = "FOO";
write;
print "OO syntax written:\n";
$fh->format_name( "FOO");
$fh->format_write;
print STDOUT Dumper(\@foo);