Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Calculating/adding byte counts of array elements

by johngg (Abbot)
on Aug 06, 2013 at 22:20 UTC ( #1048198=note: print w/replies, xml ) Need Help??


in reply to Calculating/adding byte counts of array elements

Make sure you get the length of the array element before you modify it and accumulate the byte count afterwards.

$ perl -Mstrict -Mwarnings -E ' my @array = ( q{Hello, my name is John}, q{How are you?}, q{blah (blah)}, ); my $byteCt = 0; do { my $len = length; s{^}{ sprintf q{%08d }, $byteCt }e; $byteCt += $len; } for @array; say for @array;' 00000000 Hello, my name is John 00000022 How are you? 00000034 blah (blah) $

I hope this is helpful.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048198]
help
Chatterbox?
[LanX]: whats the best way to restrict a MySQL Text Column to alphanums + underscore ?
[LanX]: CHARACTER SET?

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-03-30 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (360 votes). Check out past polls.