Think about Loose Coupling | |
PerlMonks |
Re^4: Perl array declaringby Laurent_R (Canon) |
on Jun 01, 2013 at 22:09 UTC ( [id://1036510]=note: print w/replies, xml ) | Need Help?? |
Variables can be declared as many times as you like... True only for global variables, and even then, not without warnings. Change your 'our' to 'my' and your program no longer works. You are creating new variables with the same name. Warnings inform you that the new variable masks an earlier declaration. I surely understand what you meant to say and agree with what you intended to say, Bill, but lexical variables can indeed be declared as many times as you like, provided they are not declarred in the same lexical scope. For example, the following code declares the same lexical variable four times without any error or warning:
and happily prints:
Which does not mean at all that I recommend doing that. It can be done, and is useful sometimes, but we should avoid leading to obfuscation.
In Section
Seekers of Perl Wisdom
|
|