Hi all
I have an array with strings. I want to calculate the byte count of each element and add it to the start of the next array element. The next element should start with the sum of all the byte counts
If this was my array
Hello, my name is John How are you? blah (blah)
String1: 22 bytes. String2: 12 bytes. String3: 11 bytes. Also, I want the byte counts to be 8-digit intergers. Here is how I want my output to look
00000000 Hello, my name is John 00000022 How are you? 00000034 blah (blah)
And here is the code that I am trying:
my $counting = '00000000'; $array[0] = "$counting$array[0]\n"; my $length = scalar(@array); for(my $x=1; $x <= $length; $x++) { my $size = length($array[$x-1]); $counting = $counting + $size; $array[$x] = "$counting$array[$x]\n"; }
But somehow the byte count is not what I expect it to be (always 1 more), and after the first line of output, each line starts with a space?
Any ideas? Thanks in advance for any help
In reply to Calculating/adding byte counts of array elements by Dr Manhattan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |