now that's extra weird, because introspecting with Devel::Peek reveals that the implementation is (falsely) differentiating between different kinds of 0s and NULLs.
The "other kind of 0 or NULL" is an undefined scalar.
exists differentiates between what Dump shows as SV = 0 (underlying NULL in the array) and everything else (underlying non-NULL in the array).
Say you have this variable:
my @a; $a[1] = undef; $a[2] = 123;
Devel::Peek shows
SV = PVAV(0x**6adf0) at 0x**99148 REFCNT = 1 FLAGS = () ARRAY = 0x**8b9c0 FILL = 2 MAX = 3 FLAGS = (REAL) Elt No. 0 SV = 0 Elt No. 1 SV = NULL(0x0) at 0x**69538 REFCNT = 1 FLAGS = () Elt No. 2 SV = IV(0x**696f0) at 0x**69700 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 123
(Replaced the common start of the addresses with ** to help with readability.)
The underlying array buffer of @a looks like this:
ARRAY @ 0x**8b9c0 +-------------+ Head 0 | NULL | @ 0x**69538 +-------------+ +-------------+ 1 | 0x**69538 --------->| NULL | Body +-------------+ +-------------+ 2 | 0x**69700 ------+ | 1 | REFCNT +-------------+ | +-------------+ 3 | | | | ... | FLAGS +-------------+ | +-------------+ | | SVt_NULL | TYPE | +-------------+ | | | | +-------------+ | | Head Body | @ 0x**69700 @ 0x**696f0 | +-------------+ +-----------+ +-->| 0x**696f0 --------->| ... +-------------+ | 1 | REFCNT +-------------+ | SVf_IOK|... | FLAGS +-------------+ | SVt_IV | TYPE +-------------+ | ... | +-------------+
(Technically, the body of an SVt_IV scalar is part of the same memory block as its head, but illustrating that would just complicated things needlessly.)
What follows SV = is the type of scalar.
The second number in SV = TYPE(0xBBB) at 0xHHH is the address of the scalar's head (i.e. of the scalar itself), and the first number is the address of the scalar's body. Scalars of type NULL have no body. As such, the pointer to the scalar's body in such scalars will be NULL (0x0).
In reply to Re^7: Using exists to check element in array
by ikegami
in thread Using exists to check element in array
by david
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |