Just declare the global before using it:
our $global;
Unlike my
, this does not create a new variable, but rather makes the variable available in this scope. So you could safely have code like
sub print_global{
our $global; # does not create a new variable like `my` would
print "your global is: $global\n";
}
our $global = 1234;
print_global;