The actual code/hash is more complexed. The hash is: $rotation_hash{output}{oor}{$colo}{$type}{$hostname}{file}{$filename} = <html_status_code>
As others have stated, when you ask about the existence of $foo{bar}{fubar}
, Perl automatically creates $foo{bar}
in order to test whether $foo{bar}{fubar}
exists. If you want to prevent this, you have to test to see if $foo{bar}
exists, and if it does, then test if $foo{bar}{fubar}
exists.
However, what caught my eye was your seven layer hash. When your data structures start to get that complex, you should really be using Perl Object Oriented coding. I know a lot of people are scared off by Perl objected oriented programming, but Perl is probably one of the easiest languages for people in picking up OOP.
If for nothing else, you use OOP for the same reason you use use strict;
. When I use strict;
, Perl will easily pickup where I used $foobar
as a variable in one place, but then refer to it as $fubar
in another place. You lose that protection with complex data structures. For example, you might put $rotation_hash{output}{oor}
in one place, but $rotation_hash{oor}{output}
in another place, and use strict
won't catch that. But, if you declare objects via package
, and use subroutines as methods and constructors, you gain that back.
Object oriented design will also help you eliminate the need to track your data structure. The objects handle these for you, and you can concentrate on your coding. And, you don't have to create multiple files. You can simply attach the object definitions on the bottom of your file.
There are some excellent tutorials included in the Perl documentation. If you're not familiar with OOP Perl, you should go through the tutorials and give it a try.