in reply to How to get the TOTAL length/size of an array?
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to get the TOTAL length/size of an array?
by choroba (Cardinal) on Sep 22, 2023 at 06:38 UTC | |
by LanX (Saint) on Sep 22, 2023 at 09:01 UTC | |
Re^2: How to get the TOTAL length/size of an array?
by bliako (Abbot) on Sep 22, 2023 at 08:19 UTC | |
by LanX (Saint) on Sep 22, 2023 at 08:57 UTC |