Actual code / hash is more complicated. Hash: $ rotation_hash {output} {oor} {$ colo} {$ type} {$ hostname} {file} {$ filename} = <html_status_code>
As others have said, when you ask about the existence of $foo{bar}{fubar}
, Perl automatically creates $foo{bar}
to check if $foo{bar}{fubar}
. If you want to prevent this, you need to check if $foo{bar}
exists, and if so, check if $foo{bar}{fubar}
.
However, what caught my attention was your seven-layer hash. When your data structures begin to receive this complex, you really should use Perl Object Oriented coding. I know that many people are scared by Perl's object-oriented programming, but Perl is probably one of the easiest languages for people who build OOP.
If nothing else, you use OOP for the same reason that you use use strict;
. When I use strict;
Perl will easily record where I used $foobar
as a variable in one place, but then refer to it as $fubar
in another place. You lose this protection with complex data structures. For example, you can place $rotation_hash{output}{oor}
in one place, but $rotation_hash{oor}{output}
in another place, and use strict
will not catch it. But if you declare objects through package
and use routines as methods and constructors, you will get it back.
Object-oriented design will also help you get rid of the need to keep track of the data structure. Objects process them for you, and you can focus on your coding. And you do not need to create multiple files. You can simply attach object definitions to the bottom of the file.
There are some excellent tutorials included in the Perl documentation. If you are new to OOP Perl, you should go through the tutorials and give it a try.
source share