in reply to Caller, caller, wherefore art thou, caller?

Well, considering that your problem here would be no different if you were using perl's intrinsic hashes, I don't see any reason to jump through hoops.

That is, if you were simply doing

my %hash = @array; while ( my($k,$v) = each %hash ) { last if some_condition($k,$v); }
you'd still have a dangling iterator, which you'd need to reset with an explicit call to keys %hash.

Since your hash object's semantics seem to be so similar to perl's, I'd go all the way and make them exactly the same, on the principle of least surprise.

(That being said, I don't know why you don't wrap your object in a tied class...)

Replies are listed 'Best First'.
Re^2: Caller, caller, wherefore art thou, caller?
by Ovid (Cardinal) on Oct 10, 2005 at 17:33 UTC

    For my needs, assigning the array to a hash fails because I need ordered pairs. Further, unless there is a very unusual need, I do not tie variables. If I am passing it around, programmers will see what looks like an ordinary hash and may be surprised when it doesn't do what they expect. By using a class, it's clear to the maintenance programmer that something else is going on.

    My code also allows objects as keys and has insert_before and insert_after functionality. In short, there's a number of other things which makes it preferable for my needs when a tied hash just doesn't quite get there.

    Cheers,
    Ovid

    New address of my CGI Course.