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


Comment on Re: Calculating/adding byte counts of array elements
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-09-20 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls