That's not what he was asking.

On Thu, 2003-04-03 at 10:07, BUFFERNE,VINCENT (HP-France,ex1) wrote:
> What's about:
> 
> my @foo = ( '1', '2' ,'3' );
> my $size = $#foo + 1;
> print "table size $size\n";
> 
> Ouput:
> table size 3
> 
> Vincent
> 
> -----Original Message-----
> From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
> Sent: Thursday, April 03, 2003 5:14 PM
> To: [EMAIL PROTECTED]
> Subject: How to measure Array or Hash's byte size ?
> 
> 
> 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 ?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to