Global symbol requires explicit package name? Why has this occurred and what are various cases that can cause this error?
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.
my is used for local variables, whereas our is used for global variables. More reading over at Variable Scoping in Perl: the basics.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With