如何在perl中获取以字节为单位的数组大小? [英] How to get size of array in bytes in perl?
本文介绍了如何在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:~$
这篇关于如何在perl中获取以字节为单位的数组大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文