Re: IO::Compress::Gzip creates empty file
- From: tom@xxxxxxxxxxxxxx (Tom Phoenix)
- Date: Thu, 31 Jan 2008 11:20:57 -0800
On Jan 31, 2008 10:06 AM, RICHARD FERNANDEZ <rfernandez@xxxxxxxxx> wrote:
gzip "$company.$ext.$date" => "$company.$ext.$date.gz",
BinModeIn => 1 or do {
warn "Failed to gzip file: $company.$ext.$date:
$GzipError\n";
next DOTDONE;
};
</snip>
The file "$company.$ext.$date" is created in the immediately preceding
step and definitely contains data, but the resulting compressed file is
empty, and the warn statement is not executed.
Since your code is using string expressions to generate filenames on
the fly, instead of storing the filepaths in variables, are you sure
you're getting the strings that you think you're getting? How do you
know the file "definitely contains data"? Let's take care of both
questions at once:
my $old_name = "$company.$ext.$date";
my $new_name = "$old_name.gz";
warn "File '$old_name' is empty" if -z $old_name;
warn "File '$old_name' isn't really a file" unless -f _;
unlink $new_name; # whether it's there or not
gzip $old_name => $new_name,
BinModeIn => 1
or do {
warn "Failed to gzip file: '$old_name': $GzipError";
next DOTDONE;
};
warn "File '$new_name' not created as expected"
unless -f $new_name and -s _;
I've extracted and wrapped this code to create a little test program
which works fine, that is, the resulting compressed file contains the
data I expect.
That would imply that the bug is in the other part of your code. Are
you using both 'strict' and 'warnings'?
Good luck with it!
--Tom Phoenix
Stonehenge Perl Training
.
- Follow-Ups:
- RE: IO::Compress::Gzip creates empty file
- From: Richard Fernandez
- RE: IO::Compress::Gzip creates empty file
- References:
- IO::Compress::Gzip creates empty file
- From: Richard Fernandez
- IO::Compress::Gzip creates empty file
- Prev by Date: IO::Compress::Gzip creates empty file
- Next by Date: Command line installing perl modules
- Previous by thread: IO::Compress::Gzip creates empty file
- Next by thread: RE: IO::Compress::Gzip creates empty file
- Index(es):