I seem to be having a problem STOREing multidimensional values in a TIEd hash. I'm now going round in circles because even my minimal test case (which is typically all I need to produce to fix my own problem) isn't doing what I expect.
I've reviewed How to tie multilevel (multidimensional) hash? and the Tie::Hash documentation, and I've frankly run out of brain power.
I'm ultimately trying to concatenate keys of the subhashes together where the top-level key matches ignoring case. However, the code below doesn't even warn twice (it warns once with an empty hashref), suggesting it's broken in a stupid way I can't spot, or I'm not grokking Ties.
use warnings; use strict; use Data::Dumper; use Tie::Hash; package FlatHash; use Data::Dumper; our @ISA = qw(Tie::ExtraHash); sub STORE { my $me = $_[0]; my $key = $_[1]; my $value = $_[2]; $key = lc $key; $_[0][0]{$key} = $value; if(ref $value eq "HASH") { warn Dumper($value); } else { print "This isn't a hash\n"; } } package main; tie my %flat, "FlatHash"; $flat{Monkey}{habits} = "Eating"; $flat{monkey}{habits} = "Scratching"; warn Dumper(\%flat);
Any hints gratefully received.$VAR1 = { 'monkey' => { 'habits' => ['Eating', 'Scratching'] } };
In reply to Tied multidimensional hashes by davis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |