http://www.perlmonks.org?node_id=1048198


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