如何在perl中获取以字节为单位的数组大小?
问题描述:
我需要在perl中获取数组的大小,但大小必须以字节为单位。我找不到任何功能。
提前致谢
I need get size of array in perl, but size must to be in bytes. I can not find any function for this. Thanks in advance
答
您可以使用Devel :: Size模块 - > https://metacpan.org/pod/Devel::Size
You can do this using the Devel::Size module -> https://metacpan.org/pod/Devel::Size
#!/usr/bin/perl
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";
在我的系统上显示:
bria@hel:~$ ./size.pl
Size: 765 bytes.
bria@hel:~$