Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Calculating/adding byte counts of array elements

by choroba (Chancellor)
on Aug 06, 2013 at 21:43 UTC ( #1048195=note: print w/replies, xml ) Need Help??


in reply to Calculating/adding byte counts of array elements

You are changing the array and using the changed value to count the number. Do not store the output in the array you are using to count the length:
#!/usr/bin/perl use warnings; use strict; my @array = ('Hello, my name is John', 'How are you?', 'blah (blah)', ); my $count = 0; for my $string (@array) { printf "%08d %s\n", $count, $string; $count += length $string; }
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048195]
help
Chatterbox?
[choroba]: Discipulus: I'm not sure what you really know and can code. But we have an interview process that should tell us :)

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-06-29 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (667 votes). Check out past polls.