Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Do Storable and IO::Zlib like to play together?by fokat (Deacon) |
on Nov 03, 2005 at 16:43 UTC ( [id://505431]=perlquestion: print w/replies, xml ) | Need Help?? |
fokat has asked for the wisdom of the Perl Monks concerning the following question: Dear monks: I have a (very) large archive of processed reports stored in the filesystem. Those reports are actually Perl objects that have been stored using code resembling this (heavy editing for simplification):
By using gzip/Compress::Zlib/IO::Zlib we could be saving, on average, 24% - 30% of the disk space according to the testing we've done. Then I thought that it would be very simple to ask Storable to use IO::Zlib to read the compressed, serialized objects. So, here I am writing this Template::Plugin that can read and present those objects... And banging my head against this code:
This code is throwing an exception that reads: Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.5/IO/Zlib.pm line 566. when taking the IO::Zlib path, but works beautifully when taking the IO::File branch. This is the list of things that I've tested, without success:
I can't believe that I am the only one trying to use those two modules together, although I am ready to admit that I am the only one failing :) I know that likely, something along these lines...
...would work, but I want to avoid calling external programs and all the issues that may come out of it. Specially when all the required code is already within Perl's module library. (Yes, I know that IO::Zlib will fallback to more or less that when no Compress::Zlib is around, but then I don't have to support IO::Zlib). For the record, these are the relevant versions of what I am using:
Update: Although I failed to mention this originally, I did look the code of both IO::File and Storable as suggested by frodo72 and samtregar... This code:
Is calling ->READ() when ->read() is called. That call is coming from C code, part of Storable (which I'll be looking at shortly, although I'm very weak with XS. Update: Prompted by frodo72 and samtregar, I probed deeper in the IO::Zlib and Storable code... Adding a flag, I found this: IO::Zlib AUTOLOAD=IO::Zlib::FILENO self=IO::Zlib=HASH(0x9d3c8a0) at /usr/lib/perl5/site_perl/5.8.5/IO/Zlib.pm line 567The call that is causing the exception, is happening within fd_retrieve and is looking to verify that it was passed a filehandle.
Adding this to IO::Zlib... sub FILENO { 1 }...gets rid of the exception, but causes the check of the version number of the serialized file to fail, so there's something else. Update: Following advice from sauoq, I dropped IO::Zlib in favor of PerlIO::gzip. The now fully working code looks similar to this...
Best regards -lem, but some call me fokat
Back to
Seekers of Perl Wisdom
|
|