in reply to Re^3: Mine or Ours
in thread Mine or Ours

No, that snippet is not strict-safe.

our allows you to refer to somebody's package global in unqualified manner, even when you leave the package. But this permission lasts only within lexical scope.

use strict; package First; our $foo = 42; { print $foo; # 42 package Second; print $foo; # 42, refers to $First::foo our $bar = 54; { package Third; print $foo; # 42, refers to $First::foo print $bar; # 54, refers to $Second::bar } } print $Second::bar; # 54, fully qualified. print $bar; # error: not strict-safe as the our is not in scop +e.

Replies are listed 'Best First'.
Re^5: Mine or Ours
by shmem (Chancellor) on Jan 21, 2007 at 10:08 UTC

    .oO(and the monk was enlightened.)

    Wonderful. Thanks for showing how our is lexical scoped.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}