[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: exists $foo[7] and delete $foo[7]
On Thu, Jan 13, 2000 at 03:56:28PM -0500, "Ted Ashton" wrote:
> But he is serious. And ought to be. Undefined is a state of being.
> That it is implemented by a specific value is of significance to
> those who have their hands in the guts of perl and to this point has
> been of much less significance to the average perl programmer. That
> is, to say "I defined that to be undefined" is a very strange twist.
> This "uninitialized"--as distinct from "undefined" is rather
> unsettling.
People don't seem to have very many problems with sparse files on disk,
and yet that's what happens when you lseek way past the end and then write
bytes. For the person who doesn't understand it, they don't have to. It's
almost like their were make pretend blocks on disk in between that are
filled with '\0's... big deal...
The same happens when you use "delete $array[N]"... you get an element
which isn't actually undef(), but can be used as if it was undef() anywhere
except XS code which is stupid, in which case it might generate a core dump.
But wait... you can ALREADY do things with sparse arrays...
$a[500] = 1;
Does NOT allocate 501 SV's. It allocates exactly one. The internal array
underneath may actually be "501 * sizeof(void *)" bytes big... but who
cares? Did the user worry about it before?
Oh... right... but you're worried about your little diagrams looking wrong...
Here's a diagram for them:
$array
+----+-------|
| 0 | Happy |
|----|-------|
| 1 | Days | $array[ 0] = "Happy";
|----|-------| $array[ 1] = "Days";
| 2 | Are | $array[ 2] = "Are";
|----|-------| $array[50] = "Here";
| 50 | Here |
+----+-------+
Ever considered that your little diagrams before were _WRONG_? There are
no undef()'s in @array[3..49]... they just act like undef() when they are
needed.
Not only does this allow people to have a BETTER understanding of the way
things have ALWAYS BEEN, but it allows for a future definition for some
sort of sparse array type which can be used interchangeably with the
array type (with a small speed hit).
mark
--
markm@nortelnetworks.com/mark@mielke.cc/markm@ncf.ca __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada
One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...
http://mark.mielke.cc/
- Follow-Ups from:
-
Jarkko Hietaniemi <jhi@iki.fi>
Matt Sergeant <matt@sergeant.org>
- References to:
-
Tom Christiansen <tchrist@chthon.perl.com>
Bart Schuller <schuller@lunatech.com>
Ted Ashton <ashted@southern.edu>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]