> What's about:
>
> my @foo = ( '1', '2' ,'3' );
> my $size = $#foo + 1;

you can simplify this by : $size = scalar @foo;

> print "table size $size\n";
>
> Ouput:
> table size 3

TIA, but this is not what I want... because each element is assumpted not in
same length... ie.. I am not going to get the table size...

>
> 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]
>
>


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

Reply via email to