Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 meditating upon the Monastery: (12)
As of 2015-07-06 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls