Subhashree R Subhashree R - 3 years ago 100
Perl Question

In Perl - How to know the array size in bytes?

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.

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

Answer Source

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download