dd-b has asked for the wisdom of the Perl Monks concerning the following question:
Hashes are defined to take string keys (though...stringification can make that work for random objects sometimes depending on what you expect of the value later; for just finding the object, and if the default stringification is unique among all such objects, it works).
I tried a weird thing, using lists as a hash key, and got remarkable results; Data::Dumper is claiming my hash has 3 members with the same key!
It was just playing around, and I don't see any important use for it (if I did, I'd need to understand it enough to really believe in it!; now I'm just a little curious).
This code:
use Data::Dumper; my %h1; $h1{(1, 1)} = 17; $h1{(2, 2)} = 19; $h1{('', 22)} = 23; $h1{(22, '')} = 22; my @h = (3, 4, 5); $h1{(@h)} = 44; print Dumper(\%h1);
Produces this output:
$VAR1 = { '22' => 22, '22' => 23, '11' => 17, '3' => 44, '22' => 19 };
(I observed this with perl 5, version 32, subversion 1 (v5.32.1) built for amd64-freebsd-thread-multi; I believe it's the default FreeBSD binary currently. So not an obscure environment.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Peculiar hash behavior
by jwkrahn (Abbot) on Oct 02, 2021 at 03:46 UTC | |
Re: Peculiar hash behavior
by haukex (Archbishop) on Oct 02, 2021 at 06:59 UTC | |
by dd-b (Monk) on Oct 02, 2021 at 18:08 UTC | |
by haukex (Archbishop) on Oct 02, 2021 at 19:31 UTC | |
by LanX (Saint) on Oct 02, 2021 at 19:07 UTC | |
by dd-b (Monk) on Oct 05, 2021 at 02:36 UTC | |
by jwkrahn (Abbot) on Oct 05, 2021 at 05:27 UTC | |
by AnomalousMonk (Archbishop) on Oct 05, 2021 at 04:31 UTC | |
| |
by LanX (Saint) on Oct 05, 2021 at 08:46 UTC | |
by ikegami (Patriarch) on Oct 04, 2021 at 19:30 UTC | |
Re: Peculiar hash behavior
by AnomalousMonk (Archbishop) on Oct 02, 2021 at 07:16 UTC | |
by dd-b (Monk) on Oct 05, 2021 at 02:35 UTC |