in reply to Re: the "our" declaration ?!!
in thread the "our" declaration ?!!

The strict pragma only protects the current namespace as you can see in some oneliner examples below.
# set variable, check items in PKG symbol table $ perl -Mstrict -e '$PKG::foo=1; print keys %PKG::' foo $ perl -Mstrict -e '$foo=1; print keys %main::' Global symbol "$foo" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. $ perl -Mstrict -e 'our $foo=1; print grep {/foo/} keys %main::' foo

print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Replies are listed 'Best First'.
Re^3: the "our" declaration ?!!
by ikegami (Patriarch) on Jan 20, 2009 at 12:35 UTC

    I don't understand what you are saying, and your code doesn't contradicts anything I said.

    >perl -Mstrict -le"{ package PKG; $foo=1; }" Global symbol "$foo" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. >perl -Mstrict -le"{ package PKG; no strict 'vars'; $foo=1; } print fo +r grep /foo/, keys %main::" >perl -Mstrict -le"{ package PKG; our $foo=1; } print for grep /foo/, +keys %main::" >perl -Mstrict -le"{ package PKG; no strict 'vars'; $foo=1; } print fo +r grep /foo/, keys %PKG::" foo >perl -Mstrict -le"{ package PKG; our $foo=1; } print for grep /foo/, +keys %PKG::" foo
Re^3: the "our" declaration ?!!
by rir (Vicar) on Jan 20, 2009 at 21:54 UTC
    The strict pragma only protects the current namespace

    No, remove the use strict; and the below will run without complaint.

    package X; use strict; sub one { 1 } package Y; $yy = 1; package main; exit; __DATA__ Global symbol "$yy" requires explicit package name at x line 6. Execution of x aborted due to compilation errors.
    Be well,
    rir

    Update: added initial quote for clarity