davis has asked for the wisdom of the Perl Monks concerning the following question:
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'] } };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Tied multidimensional hashes
by shmem (Chancellor) on Oct 13, 2006 at 11:33 UTC | |
Re: Tied multidimensional hashes
by xdg (Monsignor) on Oct 13, 2006 at 12:42 UTC | |
by Limbic~Region (Chancellor) on Oct 13, 2006 at 13:52 UTC | |
by MidLifeXis (Monsignor) on Oct 13, 2006 at 18:05 UTC |