[Israel.pm] Python talk

Mikhael Goikhman migo at homemail.com
Tue Dec 7 12:25:31 PST 2004


On 07 Dec 2004 19:45:18 +0200, Gaal Yahas wrote:
> 
> 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;

I used "constant" in the "use constant" context. Here is how it works.

    use constant {                                         
        INTERVAL => [ 3.1415, 92653 ],  
        PRODUCT1 => { name => "ice", price => 1E6 },
    };
    $hash{&INTERVAL} = 58979;
    $hash{&PRODUCT1} = "constant arrayref and hashref as hash keys";
    print "$hash{&PRODUCT1}, $hash{&INTERVAL}\n", keys %hash, "\n";

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list