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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048198]
help
Chatterbox?
[choroba]: Yeah, let's ban dot in INC, but add glob to it!
[Corion]: choroba: Well, at least the above is user-defined, not implicitly by Perl ;)
LanX globalization is evil! Lets Perlxit!
[stevieb]: "Yeah, let's ban dot in INC, but add glob to it!" LOL!!!

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2017-01-19 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.