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 ?

This probably does not do what your subject line indicates.  Those are not bytes it is 
measuring;
they are characters.  My advice is to not try this in Perl, because it misses the 
point.  Perl is not C.
It has a radically different paradigm regarding physical storage of data.  We do not, 
and should not,
have access to the physical storage details.

We ask the system to store a scalar--a logical, not physical, value--and link it to 
our chosen symbol,
and trust the system to get the job done.  We can then call upon that logical value by 
addressing the symbol.  AFAIK, this is all we can really know about the storage of our 
data.  Of course if you want to start with:
perldoc perlguts
and see where it leads you, you may find enough information to generate an accurate 
picture of the memory model.

Joseph


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

Reply via email to