in reply to Defining global variable in a subroutine
One way of doing what you want is to declare you shared variables as lexical variables in the most inner scope that is shared by your subroutines. In many cases, that's the file:
If you want to import variables from a different file, the usual way of doing that is with the help of Exporter:#!/usr/bin/perl use 5.010; my $global; sub set_global {$global = shift} sub get_global {$global} sub say_global {say $global}
Then in any package that wants to use any of the variables, just do:package Blabla; our @ISA = qw[Exporter]; use Exporter(); our @EXPORT = qw[$global1 $global2 $global3];
use Blabla;
|
|---|