[kw-pm] how to tell how much space an array really takes?

Robert P. J. Day rpjday at crashcourse.ca
Sat Feb 26 03:23:04 PST 2011


  not sure if this is a meaningful question but can i tell how much
space a sparse array really takes?

  say i do the following:

  $arr[0] = 10;
  $arr[10000] = 20;

i realize that perl won't allocate all those intermediate entries so
the actual "space" (can i use that word here?) is just two entries.

  if i refer to, say, $arr[1], since that entry doesn't "exist", i get
back the value "undef".  so far, so good.  however, if i assign:

  $arr[1] = undef;

then that entry really *does* have a value now, correct?  the value
"undef", not to be confused with not existing at all.

  is there a way of distinguishing between those two situations, such
that i could tell the difference?  and how much space the array
actually occupies?  or is all this meaningless?

rday

-- 

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================


More information about the kw-pm mailing list