[Dub-pm] Quick pack question.

Mcnamara John John.Mcnamara at snamprogetti.eni.it
Wed Oct 13 08:39:52 CDT 2004

Aidan Kehoe wrote:

> Hmm, thanks for that, but there's relatively little pack magic
> compared to what I had a gut feeling, was possible. Ah well. Pack
> seems more oriented to quanities greater than a byte.

Yes, in fact here is a laconic entry from perltodo (5.8.0):

   "bitfields in pack"

Anyway, it is a little late but here is a pack-ier example just to
generate some traffic:

    #!/usr/bin/perl -w

    print my $str = sprintf "%032b", 123456789;

    my $template_A = 'A7' x (length($str) / 7);
    my $template_B = 'B7' x (length($str) / 7);

    my @nums = map    {$_ >> 1}
               unpack 'C*',
               pack   $template_B,
               unpack $template_A, $str;

    printf "%07b %d\n", $_, $_ for @nums;


    0000011 3
    1010110 86
    1111001 121
    1010001 81

> here's the PHP (don't look so shocked,

"My eyes, my eyes. The goggles do nothing". :-)


*************************E-MAIL CONFIDENTIALITY FOOTER**********************
This message may contain confidential information and must not be copied,
disclosed or used by anybody other than the intended recipient.
If you have received this message in error, please notify us writing
to postmaster at snamprogetti.eni.it and delete the message and any copies of it.
Thank you for your assistance.

More information about the Dublin-pm mailing list