If you want to know how much is currently used by some structure, use Devel::Size.
| [reply] |
Perl variables will grow as needed. Sometimes it is useful to size an array or hash to accommodate a large number of values, to prevent Perl from repeatedly having to allocate additional space.
# presize a hash:
keys(%hash) = 10_000;
# size an array:
my @array;
$#array = 10_000;
Sizing an array to be shorter than it currently is will truncate the array.
| [reply] [d/l] |
As TGI says: "Perl variables will grow as needed. " There is a lot contained in that statement. Unlike C, perl is a dynamic language. It keeps track of memory allocations for you. You rarely need to worry about it. All data types, whether scalars, arrays or hashes will have their memory allocated dynamically and will grow as needed. Perl even moves the storage around as needed when the item outgrows its allocated block and need a larger contiguous block.
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s
|-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,,
$|=1,select$,,$,,$,,1e-1;print;redo}
| [reply] [d/l] |