Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, <code>undef</code> is supposed to be a flyweight value, meaning that all references to it point to the same datum. You don't get that for other literals. You still need the overhead of the slot that references it though. However, I'm not seeing it save any memory for me on Perl 5.10 or 5.11 on Mac OS X. While <code>perl</code> may not be using more memory in the <code>undef</code> case, I bet it's anticipating using more memory so it grabs it anyway. However, I'm not keen on investigating memory use in the internals right now.</p> <p><a href="http://search.cpan.org/dist/Devel-Peek" rel="nofollow noreferrer">Devel::Peek</a> is pretty handy for showing these sorts of things:</p> <pre><code>#!perl use Devel::Peek; my $a = undef; my $b = undef; Dump( $a ); Dump( $b ); my %hash = map { $_, undef } 1 .. 3; $hash{4} = 'Hello'; Dump( \%hash ); </code></pre> <p>The output looks a bit scary at first, but you see that the <code>undef</code> values are <code>NULL(0x0)</code> instead of individual string values (<code>PV</code>):</p> <pre><code>SV = NULL(0x0) at 0x100208708 REFCNT = 1 FLAGS = (PADMY) SV = NULL(0x0) at 0x100208738 REFCNT = 1 FLAGS = (PADMY) SV = RV(0x100805018) at 0x100805008 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x100208780 SV = PVHV(0x100809ed8) at 0x100208780 REFCNT = 2 FLAGS = (PADMY,SHAREKEYS) ARRAY = 0x100202200 (0:5, 1:2, 2:1) hash quality = 91.7% KEYS = 4 FILL = 3 MAX = 7 RITER = -1 EITER = 0x0 Elt "4" HASH = 0xb803eff9 SV = PV(0x100801c78) at 0x100804ed0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x100202a30 "Hello"\0 CUR = 5 LEN = 8 Elt "1" HASH = 0x806b80c9 SV = NULL(0x0) at 0x100820db0 REFCNT = 1 FLAGS = () Elt "3" HASH = 0xa400c7f3 SV = NULL(0x0) at 0x100820df8 REFCNT = 1 FLAGS = () </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload