Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Fast string construction

by johngg (Canon)
on Apr 07, 2011 at 13:59 UTC ( [id://898065]=note: print w/replies, xml ) Need Help??


in reply to Fast string construction

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://898065]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found