[Israel.pm] Python talk

Gaal Yahas gaal at forum2.org
Tue Dec 7 09:45:18 PST 2004

On Tue, Dec 07, 2004 at 05:34:59PM +0000, Mikhael Goikhman wrote:
> > I forgot to mention that this approach, apart from potentially being
> > dangerous due to the ref-reuse prolem, has the obvious limitation that
> > applicatively equivalent keys will not match elements. I *must* have
> > $time to restore the value. I will be disappointed if I do
> > 
> >     $time2 = [ 100, 200 ];
> > 	return $CAA->{$time2}; #undef
> > 
> > What I typically want for object keys is that they associate to the same
> > element if they pass (in Javaesque parlance) an isEqual test.
> It seems you completely missed my note that this limited technique only
> works "if the keys are constant arrays and not variable arrays". :)

Indeed I did not!

@constant_array = ( 100, 200 );
$key1 = \@constant_array;
$key2 = \@constant_array;

It's the reference that must be constant, not the array. In fact you can
change the value of the array and the hash element will still be as
addressable as it was before!

> I actually used this. Some external module had distinct array constants
> defined and I used them as hash keys.

I never said this was useless. Like many techniques, it can be quite useful
for some uses, and quite dangerous for others. (An example of a commonly
used technique that falls into this category is the integer type in c.
Nobody in their right minds wants to stop using int for, say, loops, if
they know their index isn't going to overflow.)

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list