in reply to Calculating/adding byte counts of array elements
This alternate also works:
#!/usr/bin/perl use 5.016; use warnings; # 1048190 my @arr = ("Hello, my name is John", "How are you?", "blah (blah)", "", "blivitz is in the last line.", ); my $count = 0; for my $line(@arr) { say $count . " " . $line; $count += length($line); }
Producing:
C:\>1048190.pl 0 Hello, my name is John 22 How are you? 34 blah (blah) 45 45 blivitz is in the last line.
Use of printf or sprintf is left as an exercise for the OP... altho the initialization of $counting = '00000000'; should be satisfactory too.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calculating/adding byte counts of array elements
by AnomalousMonk (Archbishop) on Aug 07, 2013 at 07:04 UTC | |
by Happy-the-monk (Canon) on Aug 07, 2013 at 07:41 UTC |