Rob Dixon said:
> Li Ngok Lam wrote:
>> My method sounds stupid, but still works :
>>
>> my @array = ('123', 'abc', 'def', 1..9);
>> my $len_of_array = 0 ;
>> foreach my $elem(@array)
>> { $len_of_array += length($elem) }
>> print $len_of_array ; # I got '18'
>>
>> my %hash = (1=>2, 2=>3, 3=>4);
>> foreach my $key(keys(%hash))
>> { $len_of_hash += length($key) + length($hash{$key}) }
>> print $len_of_hash ; # I got '6'
>>
>> I suppose there should be another better and faster way to done this,
>> any suggestion ?
>
> It really depends on what you expect to do with the result that
> you're getting.
Rob is correct, but the following code is another way to get the results
you had:
local $" = "";
print length "@array";
my @tmp = %hash;
print length "@tmp";
However, I don't think there's anything particularly wrong with your code,
which can't be said for mine.
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]