in reply to Global symbol x requires explicit package name at main.pl

On very rare occasion, there's a valid reason to make a package variable global (or declare it with 'our', as toolic recommended.) If you do so, then you can access it without exporting or any other special mechanisms, simply by specifying the package name:

package test; $x = "Hi"; # Or $::x = "Hi"; package main; print $test::x;

--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^2: Global symbol x requires explicit package name at main.pl
by beanryu (Novice) on Aug 19, 2010 at 00:56 UTC
    thanx for the advice, I used the double colon method and assign the package variable to a local variable. However, it still didn't work. Then I change "use test" to "require("test.pm")" and it worked... thanx But this is still very magical, kinda confusing...