develooper Front page | perl.perl5.porters | Postings from July 2005

[perl #36538] perlfunc/our contradicts itself

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
July 13, 2005 14:08
Subject:
[perl #36538] perlfunc/our contradicts itself
Message ID:
rt-3.0.11-36538-117234.12.6262760253157@perl.org
# New Ticket Created by  Michael G Schwern 
# Please include the string:  [perl #36538]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=36538 >


perlfunc/our sez:

  The "our" declaration has no semantic effect unless "use strict vars" is 
  in effect, in which case it lets you use the declared global variable 
  without qualifying it with a package name.

Ok, so that means any program should work the same with or without the
"our" statement if 'strict vars' is off.

	our $foo = 42;  # or just $foo 42
	print $foo;

Except its not true.  perlfunc/our goes on to contradict itself in the
next paragraph.

  An "our" declaration declares a global variable that will be
  visible across its entire lexical scope, even across package
  boundaries.

Which means:

	package Bar;
	our $foo = 42;
	package Foo;
	print $foo;

acts different from

	package Bar;
	$foo = 42;
	package Foo;
	print $foo;

strict or not.

I think the thing to do is to reword the first statement such that it no
longer declares our has no effect unless strict is on.

  When C<use strict vars> is in effect, the C<our> declaration lets you
  use the declared global variable without qualifying it with a package
  name.


-- 
Michael G Schwern     schwern@pobox.com     http://www.pobox.com/~schwern
'All anyone gets in a mirror is themselves,' she said. 'But what you
gets in a good gumbo is everything.'
	-- "Witches Abroad" by Terry Prachett

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