How to get size of array in bytes in perl?

后端 未结 1 1510
深忆病人
深忆病人 2021-01-25 15:05

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条回答
  • 2021-01-25 15:42

    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:~$
    
    0 讨论(0)
提交回复
热议问题