Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to add to hash of a hash of an array. Confused.com!

by roboticus (Chancellor)
on Jun 13, 2013 at 11:38 UTC ( #1038723=note: print w/replies, xml ) Need Help??


in reply to How to add to hash of a hash of an array. Confused.com!

Doozer:

If the item doesn't exist, you're just going to create it anyway, so why not just use:

push @{$hash{A1}{B2}{C1}}, $item;

Without showing more of your code, we can't be sure exactly what your problem is. I'm suspecting that it's due to the fact that sometimes your B-level variable is a string and sometimes it's a hash reference. Perhaps $hash{A1}{B2} was a string a moment before executing the code you've shown--that would be enough to cause the problem:

$ perl ttt3.pl Can't use string ("") as a HASH ref while "strict refs" in use at ttt3 +.pl line 7. * /W/P/PM/ monitor_saints; check TODO_LIST $ cat ttt3.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; $hash{A1}{B2} = ""; if (exists $hash{A1}{B2}{C1}) { print "Baz!\n"; }

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038723]
help
Chatterbox?
[Corion]: marto: Ow! You got hit by the storm that is bringing warm weather to me ...
[1nickt]: marto Good to hear that was the worst of it for you...
[marto]: 1nickt the worst I'm aware of at the moment :P
LanX .♩..♬ ... Another one bites the Sahara dust ...
marto wonders what fresh hell the firefox update has brought, apart from maxing out CPUs

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-10-17 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (230 votes). Check out past polls.

    Notices?