JediWombat:

It looks like IO::Uncompress::Bunzip2 handles the $/ variable just fine, so it shouldn't have any problem reading blocks:

#!env perl use strict; use warnings; use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error); $/="\n\n"; my $z = new IO::Uncompress::Bunzip2("zzzzz.bz2") or die "Argh! $Bunzip2Error\n"; my $cnt=0; while (my $buff = $z->getline()) { ++$cnt; my $len = length($buff); print "BLOCK: $cnt\nLEN: $len\n$buff\n\n\n\n"; last if $cnt>10; }

So perhaps I'm misunderstanding your problem....

Nevermind what I wrote below. When I saw you asking about reading by blocks, I thought you meant fixed-sized blocks, not delimited as your code shows. Sorry about that.


You should be able to read fixed-size blocks like this:

#!env perl use strict; use warnings; use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error); #my $z = new IO::Uncompress::Bunzip2("zzzzz.bz2", {BlockSize=>512}) #my $z = new IO::Uncompress::Bunzip2("zzzzz.bz2", BlockSize=>512) my $z = new IO::Uncompress::Bunzip2("zzzzz.bz2") or die "Argh! $Bunzip2Error\n"; my $buff; my $cnt=0; while (my $status = $z->read($buff, 512)) { ++$cnt; my $len = length($buff); print "BLOCK: $cnt\nLEN: $len\n$buff\n\n\n\n"; last if $cnt>10; }

NOTE: The BlockSize argument in the constructor didn't work, I tried it both as a hashref and as just a couple extra arguments, as above. But the read method accepts a block size argument, so you can still read fixed sized blocks. If anyone sees what I did wrong on the constructor, I'd like to hear what it is.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Searching large files a block at a time by roboticus
in thread Searching large files a block at a time by JediWombat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.