[sf-perl] mine vs ours

David Alban extasia at extasia.org
Thu Dec 6 11:52:31 PST 2007


I want bar() to access a constant i define in foo().  It can't be
defined outside of foo() because in my "real" program, it depends on a
value computed in foo().  In fact there's going to be a lot of
routines called by foo() that will need

With the my() statement uncommented, it complains "Global symbol
"$SOME_CONSTANT" requires explicit package name".  With the our()
statement uncommented it seems to work.


use strict;
use warnings;

use Readonly;


sub foo {
  # Readonly::Scalar our $SOME_CONSTANT => 'FOOBAR';
  Readonly::Scalar my $SOME_CONSTANT => 'FOOBAR';
} # foo

sub bar {
  print "$SOME_CONSTANT\n";
} # bar

So it would seem to me to use our() rather than my() for this.  Any
reason why I shouldn't?  Sanity checking...

Live in a world of your own, but always welcome visitors.

More information about the SanFrancisco-pm mailing list