I wonder if you could use vec instead. I don't think you would need to initialise the string then as it would, I think, be automatically extended at need. I think it also stores bits in the same order as pack q{N}, ...

knoppix@Microknoppix:~$ perl -E ' > vec( $str, 1, 32 ) = 0xfffff; > say unpack q{b*}, $str; > vec( $str, 3, 32 ) = 0xf; > say unpack q{b*}, $str;' 0000000000000000000000000000000000000000111100001111111111111111 0000000000000000000000000000000000000000111100001111111111111111000000 +0000000000000000000000000000000000000000000000000011110000 knoppix@Microknoppix:~$ perl -E ' > vec( $str, 0, 32 ) = 0xfffff; > say unpack q{b*}, $str; > say unpack q{b*}, pack q{N}, 0xfffff;' 00000000111100001111111111111111 00000000111100001111111111111111 knoppix@Microknoppix:~$

I hope this is useful.

Cheers,

JohnGG


In reply to Re: Fast string construction by johngg
in thread Fast string construction by citromatik

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.