How to get size of array in bytes in perl?

对着背影说爱祢 提交于 2020-01-21 20:24:25

问题


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


回答1:


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";

On my system this prints:

bria@hel:~$ ./size.pl
Size: 765 bytes.
bria@hel:~$


来源:https://stackoverflow.com/questions/27290816/how-to-get-size-of-array-in-bytes-in-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!