Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
i don't understand why the package variables are vivificated _before_ the require.
it looks like aaa::var defines a variable in namespace aaa. (and vivificates it if the package is not yet defined)
thanks
:::::::::::::: perlexe.pl :::::::::::::: #!/usr/bin/perl use strict; use warnings; BEGIN { $perlpkg::var_our = "foo"; $perlpkg::var_my = "foo"; $perlpkg::var_lcl = "foo"; } print "\noml : $perlpkg::var_our $perlpkg::var_my $perlpkg::var_lcl\n" +; require "perlpkg.pm"; $perlpkg::var_our = "bar"; $perlpkg::var_my = "bar"; $perlpkg::var_lcl = "bar"; print "oml : $perlpkg::var_our $perlpkg::var_my $perkpkg::var_lcl\n\n" +; :::::::::::::: perlpkg.pm :::::::::::::: package perlpkg; our $var_our; my $var_my ; local $var_lcl; print " oml : $var_our $var_my $var_lcl\n"; $var_our = "baz"; $var_my = "baz"; $var_lcl = "baz"; print " oml : $var_our $var_my $var_lcl\n"; 1; STDOUT : oml : foo foo foo oml : foo oml : baz baz baz oml : bar bar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: vivification of package variables
by GrandFather (Saint) on Sep 21, 2010 at 05:42 UTC | |
|
Re: vivification of package variables
by ikegami (Patriarch) on Sep 21, 2010 at 05:34 UTC | |
|
Re: vivification of package variables
by JavaFan (Canon) on Sep 21, 2010 at 09:56 UTC |