Frankly, Perl sucks static-variable-wise. They're not directly supported, and must be hacked-over with my() in a BEGIN block. It didn't feel right.

Bah. Heresy. Statics in modules done need a BEGIN block, they dont even need an enclosing scope unless you are being pedantic. And they can be shared amongst any arbitrary set of procedures. So Id say they are pretty powerful actually.

Incidentally you wrote this:

my $stream = BitStream::new("bigbinfile");

Thats not a method call. Thats a procedure call.

Anyway, I whipped this together before I realized that you had already gone down this road. (Really must read nodes a bit more thoroughly before replying :-)

package File::Bitstream; use strict; use warnings; sub new { my ($class,$file)=@_; open my $fh,"<",$file or die "Cant read '$file':$!"; binmode $fh; return bless { file=>$file, fh=>$fh, buffer=>'', chunk=>1024 },$cl +ass; } sub get_bits { my ($self,$bits)=@_; while (!eof($self->{fh}) and length($self->{buffer})<$bits) { my $chars=''; read($self->{fh},$chars,$self->{chunk}); $self->{buffer}.=unpack "B*",$chars; } return length($self->{buffer}) ? substr($self->{buffer},0,$bits,'' +) : undef; } 1; my $o=File::Bitstream->new($0); my $bits=''; print $bits,$/ while defined($bits=$o->get_bits(13));

---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi



In reply to Re: evolving an OO solution for a bitstream by demerphq
in thread evolving an OO solution for a bitstream by spurperl

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.