Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Are pseudo-hashes worth the effort?

by autark (Friar)
on Dec 13, 2000 at 05:54 UTC ( #46369=note: print w/replies, xml ) Need Help??

in reply to Are pseudo-hashes worth the effort?

"Is pseudo-hashes usefull ?" - You are certainly not the first person to ask that question :-)

I don't remember the exact reason why that feature was introduced. However, some of the pro opinions was:

  • pseudo-hashes has a smaller memory footprint than regular hashes.
  • Faster runtime access to fields, $pseudo->{foo} will compile to $pseudo->[15]
  • Compile time checking of object attributes ($pseudo->{errur})
IIRC, it was once a consistency problem between pseudo-hashes and arrays that led to the delete and exists functions being able to take array elements as well: @a = (1,2,3); delete $a[1] Now, this "little" feature introduces something interesting. We can "delete" an array element - but what does that mean ?
@a = (1,2,3); delete $a[1]; print "($_)\n" for @a;
This would produce the following:
(1) () (3)
Aha! So delete $a[1] must be the same as $a[1] = undef then ? Let's check that statement:
@a = (1,2,3); delete $a[1]; print "I'm ", exists $a[1] ? "here" : "gone"; @b = (1,2,3); $b[1] = undef; print "I'm ", exists $b[1] ? "here" : "gone";
And indeed, this invalidates my previous statement. For the output is:
I'm gone I'm here
So delete $a[1] is not the same as $a[1] = undef. Hm, isn't that strange ? Well, the story is this, when we use undef we set the variable to the special value undef. When we use delete it does not set our variable to the special value undef, but to the special special value called uninitialized. Uninitialized means that the variable has not been set at all.

This may seem strange but then again, pseudo-hashes and delete/exists on arrays is an experimental feature. (delete and exists on arrays was added in 5.6 IIRC).

If you ask me it is a good reason pseudo-hashes is experimental, if you are not interested in my opinion, then maybe the opinion of our current pumpkin for the development track of perl (5.7) might interest you :-)


Replies are listed 'Best First'.
Re: Are pseudo-hashes worth the effort?
by Dominus (Parson) on Dec 14, 2000 at 09:39 UTC
    exists() and delete() on arrays was Schwern's stupid idea. He must be severely punished.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://46369]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-11-30 06:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found