in reply to Perl syntax

our makes a lexically scoped alias to a package variable. So,
package B; our $d = 1;
means that for the rest of the lexical scope (in your case, the current file (and of course not if it's hidden by a definition in an inner scope)), $d is an alias to $B::d. So, your code is equivalent to:
package A; package B; $B::d = 1; package C; package D; print $B::d;
Don't worry if you find it confusing; many people do. Luckely, you don't have to use it. I find myself using it only for variables like @ISA and @EXPORT.