develooper Front page | perl.perl5.porters | Postings from December 2014

[PATCH] perlfunc: document immediate stricture effect of "our"

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
December 2, 2014 03:14
Subject:
[PATCH] perlfunc: document immediate stricture effect of "our"
Message ID:
ecafefb82337acf1046f535da14a6fc0293f70b5.1417490045.git.pagaltzis@gmx.de
---
 pod/perlfunc.pod | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 9347b60c23..5fe4b3d06c 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -4369,7 +4369,8 @@ existing variable: a package variable of the same name.
 
 This means that when C<use strict 'vars'> is in effect, C<our> lets you use
 a package variable without qualifying it with the package name, but only within
-the lexical scope of the C<our> declaration.
+the lexical scope of the C<our> declaration. This applies immediately--even
+within the same statement.
 
     package Foo;
     use strict;
@@ -4395,6 +4396,16 @@ package variables spring into existence when first used.
 
     print $Foo::foo; # prints 23
 
+Because the variable becomes legal immediately under C<use strict 'vars'>, so
+long as there is no variable with that name is already in scope, you can then
+reference the package variable again even within the same statement.
+
+    package Foo;
+    use strict;
+
+    my  $foo = $foo; # error, undeclared $foo on right-hand side
+    our $foo = $foo; # no errors
+
 If more than one variable is listed, the list must be placed
 in parentheses.
 
-- 
2.1.2


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About