Hello monks.
I suppose recursive 'uses' should be avoided in general cases, but still, I'd like to understand what's going on with this simple code: A1 and A2 are using C, which uses A2. Warning and strict are used in all files.
File A1.pm
package A1; use A2; use C; sub functionA { print "In A1: ".C::TYPE->{VEG}."\n"; A2::functionA(); }
File A2.pm
package A2; use C; sub functionA { print "In A2: ".C::TYPE->{VEG}."\n"; }
File C.pm
package C; use A2; use constant { TYPE => { FRUIT => 1, VEG => 2, MEAT => 3, }, };
Now we can test:
use A2; A2::functionA(); # prints "In A2: 2"
and
use A1; A1::functionA(); # prints "In A1: 2\nIn A2: 2"
Right. But if we inverse the order of 'use' in A1.pm, so C is 'used' before A2, the second test leads to a non-understanding of external constant TYPE: "Can't use bareword ("C::TYPE") as a HASH ref while "strict refs" in use at A2.pm line 7". Why so?
Question 2: If we keep this order, I can fix the problem by calling in A2.pm "C->TYPE->{VEG}" instead of "C::TYPE->{VEG}". Enlightenments welcome! : )
Cheers.
Locinus (perl v5.12.3 built for MSWin32-x86-multi-thread)
In reply to Behaviour on recursive use by locinus33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |