tags:

views:

45

answers:

2

Global symbol requires explicit package name ? why this is occured and what are various type it can cause this error ?

+7  A: 

Have a look at perldiag:

Global symbol "%s" requires explicit package name

(F) You've said "use strict" or "use strict vars", which indicates that all variables must either be lexically scoped (using "my" or "state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").

musiKk
+1  A: 

In order to specifically say what caused it in your code, you would need to post your code.

The error is outputted and your script is stopped because you've got use strict or a derivative of it. The error occurs because your program is calling a variable out of scope.

  1. You may have used my or local inside a sub procedure/function, but are trying to use it inside another procedure, or outside the function call.

     sub foo{
        my $bar=0; 
        our ($soap) = 1;
     }
     foo();
     print $bar        , "\n";  # does not work w/ strict -- bar is only in the scope of the function, not globally defined
     print $main::bar  , "\n";  # will run, but won't be populated
     print $soap       , "\n";  # does not work w/ strict -- the package isn't defined
     print $main::soap , "\n";  # will run and work as intended because of our
    
vol7ron