An array has only the "size" of scalar @array because in reality the members are only pointers to scalars.
But a scalar can be a reference to an even deeper data structure.
The correct answer would hence be using Devel::Size to get the total memory of a deep data structure.
If you only want the total length of characters of a deep data structure, you can (ab)use serializers Data::Dumper or similar for an approximation, with the benefit that this would "work" for more deeply nested structures too
DB<20> use Data::Dumper DB<21> @a=("abc", "cd", "e", "fg", "hi", "hello world"); DB<23> $Data::Dumper::Terse = 1 DB<24> $Data::Dumper::Indent = 0 DB<25> p Dumper @a 'abc''cd''e''fg''hi''hello world' DB<26> p length(Dumper @a)-2*@a 21 DB<27>
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In reply to Re: How to get the TOTAL length/size of an array?
by LanX
in thread How to get the TOTAL length/size of an array?
by Polyglot
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |