Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global symbol requires explicit package name

Tags:

perl

Global symbol requires explicit package name? Why has this occurred and what are various cases that can cause this error?

like image 822
Tree Avatar asked Jun 29 '10 14:06

Tree


People also ask

How do I declare a global variable in Perl?

Global variables can directly use and are accessible from every part of the program. Example 1: The variable $name is declared at the beginning of the code. It will be visible till the end of the file everywhere. Even inside blocks. Even if those are in the function declarations.

What is my and our in Perl?

my is used for local variables, whereas our is used for global variables. More reading over at Variable Scoping in Perl: the basics.


1 Answers

It may also happen when the statement before is not complete.

use strict;  sub test;  test()  # some comment my $x; 

perl now complains with following error message:

my " Global symbol "$x" requires explicit package name 

The error is not in the declaration of "my", but at the missing semicolon (;) at test().

like image 109
koppor Avatar answered Sep 20 '22 14:09

koppor