Subject: | Behavior of eof with empty files is different from the normal IO::File->eof() |
I've noticed a slightly little difference between the handling of empty
files from IO::File and IO::Uncompress::(Gunzip||Bunzip2).
Empty files don't return a eof at once after opening an empty file.
Here's some pseudocode:
touch empty ; gzip empty
$handle = IO::Uncompress::Gunzip->new( 'empty.gz ');
print $handle->eof(); # prints 0, should be 1
print $handle->getline(); # prints empty string, should be undef
Here's the behavior with IO::File:
touch empty
$handle = IO::File->new( 'empty');
print $handle->eof(); # prints true
print $handle->getline(); # produces undefined warning
I've attached a sample script that will print the above values.
Here the mini usage for this script:
1) touch empty ; gzip empty ; touch empty
2) perl uncompress-bug.pl empty ; perl uncompress-bug.pl empty.gz
Then you will notice the difference in the output.
Thanks for your work.
Subject: | uncompress-bug.pl |
#!/usr/bin/perl
use strict;
use warnings;
use IO::Uncompress::Gunzip;
use IO::Uncompress::Bunzip2;
use IO::File;
my $filename = shift || die;
my $line;
my $handle;
if ($filename =~ /.gz$/ )
{
$handle = IO::Uncompress::Gunzip->new( $filename );
}
elsif ($filename =~ /.bz2$/ )
{
$handle = IO::Uncompress::Bunzip2->new( $filename );
}
else
{
$handle = IO::File->new( $filename )
}
printf "eof .... : %s\n", $handle->eof() ? 1 : 0;
print "\n";
print "reading...\n\n";
$line = <$handle>;
printf "eof .... : %s\n", $handle->eof() ? 1 : 0;
printf "line ... : %s\n", defined $line ? 'defined' : 'undefined';
print "\n";
print "reading...\n\n";
$line = <$handle>;
printf "eof .... : %s\n", $handle->eof() ? 1 : 0;
printf "line ... : %s\n", defined $line ? 'defined' : 'undefined';