in reply to Use of uninitialized variables?

The comment from your co-worker may be confusing package variables with lexical my variables, which are completely different. In a nutshell, "my @var = ()" can't overwrite a package variable named @var.

I don't see any problem with initializing everything upon creation. I prefer to use exceptions to indicate there's a problem rather than magic values, undef or otherwise. I initialize things a lot myself, now that I think about it. This is a habit I've carried over from C.

I'd ask your co-worker to come up with some code that demonstrates the problem.

Replies are listed 'Best First'.
Re^2: Use of uninitialized variables?
by Anonymous Monk on Jun 11, 2008 at 18:41 UTC
    I agree with kyle about the probable confusion on the part of the OP's co-worker concerning the purpose and behavior of package and lexical variables.

    Furthermore, if you have a Perl 5 'class', it is probably based on the package mechanism. If in this class (i.e., package) there exist package and lexical (i.e., my) variables with the same name, this probably represents a problem in and of itself: someone is going to get terribly confused and the whole affair will end in tears.

      And yet furthermore, the existence of a package (hence global) variable is, in and of itself, cause for suspicion during code review or at any other time.