解决方法
您可以使用Devel :: Size模块执行此操作 – >
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:~$