develooper Front page | perl.perl5.porters | Postings from December 2001

BEGIN { our }

Thread Next
From:
John P. Linderman
Date:
December 24, 2001 04:23
Subject:
BEGIN { our }
Message ID:
200112241223.HAA67655@raptor.research.att.com
Time to flaunt my ignorance again.  If I run

    use strict;
    BEGIN { our @sortopts = qw( _quicksort stable ); }
    use sort @sortopts;
    print(sort::current() . "\n");

I am told

    Variable "@sortopts" is not imported at bu line 3.
    Global symbol "@sortopts" requires explicit package name at bu line 3.
    BEGIN not safe after errors--compilation aborted at bu line 3.

However, if I simply remove the "use strict;"
the script runs fine, yielding

    quicksort stable

as proof that @sortopts is visible to the use sort.
I can silence the warnings with a

    use vars qw( @sortopts );
    BEGIN { @sortopts = qw( _quicksort stable ); }

but I'm puzzled about the behavior.  If the scope of our @sortopts
were limited to the BEGIN, the use sort should have failed,
and if it is not so limited, the warning seems out of place.  -- jpl

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