more useful options | |
PerlMonks |
Iterating through a HoHoH ... does a particular sub-hash exist?by jedikaiti (Hermit) |
on Apr 05, 2010 at 17:29 UTC ( [id://832862]=perlquestion: print w/replies, xml ) | Need Help?? |
jedikaiti has asked for the wisdom of the Perl Monks concerning the following question: I have a hash, much like the one below:
What I want to do is to loop through each command (key) in the hash, and do X if it has one or more subfields, and Y if it has 0 subfields. So I have a foreach loop in my code (below), with an if/else statement. Problem is, I can't get the if/else conditions right. I have tried it as below, and I have tried if (not defined $cmdData->{$cmd}{subfields}). In both cases, it prints all the command names, followed by "defined".
Yes, I can change the hash I'm working with - sort of. I have a preprocessing script that is compiling a whole mess of hashes of the same format into one big one in a file (so it's easier to iterate through later). I can change that script to output something nicer, but I still need to know how to tell if there are subfields or not (this is how they appear in the original hashes I'm pulling from) so I can fix them. Thanks a million, Monks!
Kaiti Swiss Army Nerd
Back to
Seekers of Perl Wisdom
|
|