The following is what I want to do, but this isn't how I want to do it because it is incredibly slow. Seems like there should be an easier (faster) way:
[perl]
for (@foo) {
$total+=length($_);
}
[/perl]
Maybe you can count the length of the array as you construct it? Or if it comes from an external source, get that source to do it for you. In C programming it's common to pass the length of a string as well as the string itself, to save having to find the length later on.
There's a bug in the $size=length("@array") also... you get a whole load of padding counted.
[perl]
#!perl
@array = ("Hello","Frogs","Toads","And","other","Amphibians");
for (@array) {
$size += length($_);
}
print "V1 - $size\n";
$size = length("@array");
print "V2 - $size\n";
$size = length("@array") - $#array;
print "V3 - $size\n";
[/perl]
$ ./test.pl
V1 - 33
V2 - 38
V3 - 33