I want to double-check that it is correct to use "our" to import globals.

#!/usr/bin/perl -w

use strict;

BEGIN {
   our $foo = 'foo';
}

sub something {
   our $foo;
   our $bar;

  ...at this point I can see 'foo' and 'bar' values.
}

END {
  our $bar = 'bar';
}

If I do *not* import with "our $foo;" inside main::something(); I get
the following errors:


Variable "$foo" is not imported at ./script.pl line xx
Variable "$bar" is not imported at ./script.pl line yy

Global symbol "$foo" requires explicit package name at ./script.pl line xx.
Global symbol "$bar requires explicit package name at ./script.pl line yy.


Is this the correct way to import globals?

$perldoc vars

says...:

NOTE: For variables in the current package, the functionality provided by this
      pragma has been superseded by "our" declarations, available in
Perl v5.6.0 or
      later.  See "our" in perlfunc.



--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to