in reply to unblessed reference problem

gdolph:

You may want to rearrange your hash so that the domain is the *last* rather than the first key. That way, you can do:

foreach my $domain (sort {$a cmp $b} keys %{$$hash{$var1}{$var2}}) + { my $value = $$hash{$var1}{$var2}{$domain} }

...roboticus

Replies are listed 'Best First'.
Re^2: unblessed reference problem
by roboticus (Chancellor) on Mar 26, 2010 at 12:09 UTC

    I forgot to mention that you can use a continuation closure, something like this (untested):

    my $test = sub { my $hr=shift; return $hr->{$var1}{$var2} }; foreach my $domain (sort {$a cmp $b} keys %{$hash}) { my $value = &{$test}($$hash{$domain}); }

    ...roboticus

    Update: correction, as noted by chromatic. (I didn't make the other change, as it's merely ugly rather than wrong, and chromatic shows the nicer looking version anyway.)

      Two small nits. First, that isn't a continuation. It's a closure. (It closes over variables, not control flow.)

      Second, your dereferencing syntax could be much clearer:

      my $value = $test->($hash->{$domain});
Re^2: unblessed reference problem
by gdolph (Novice) on Mar 26, 2010 at 12:13 UTC

    Would that I could! If could just then hand a reference to that particular branch, unfortunately to do so would require a major re-working of everything further up so wouldn't be worth the effort