在Perl中 - 如何知道以字节为单位的数组大小? [重复]

时间:2022-01-22 21:28:08

This question already has an answer here:

这个问题在这里已有答案:

I Have stored a decoded json in an array. I need to know the array size in bytes, so that I can parse it. Please suggest me a way to know the size of an array in perl.

我已将解码的json存储在数组中。我需要知道数组的大小,以字节为单位,以便我可以解析它。请建议我一种方法来了解perl中数组的大小。

Note: It is not the number of elements in array. I want size in bytes or mb

注意:它不是数组中的元素数。我想要以字节或MB为单位的大小

1 个解决方案

#1


2  

From this example

从这个例子

use strict;
use warnings;
use Devel::Size qw(total_size);

my @arr = (1, 2, 3, "Foo", "Bar", "Baz", [4, 5, 6], {xyz => 2048});

print "Size: ", total_size(\@arr), " bytes.\n";

You would therefore need Devel::Size

因此,你需要Devel :: Size

If you are unsure on how to install modules from CPAN, go to this link

如果您不确定如何从CPAN安装模块,请转到此链接

#1


2  

From this example

从这个例子

use strict;
use warnings;
use Devel::Size qw(total_size);

my @arr = (1, 2, 3, "Foo", "Bar", "Baz", [4, 5, 6], {xyz => 2048});

print "Size: ", total_size(\@arr), " bytes.\n";

You would therefore need Devel::Size

因此,你需要Devel :: Size

If you are unsure on how to install modules from CPAN, go to this link

如果您不确定如何从CPAN安装模块,请转到此链接