package Sharedvariables; use strict; use warnings; sub new { my $class = shift; my $self = { # store here all the variables you want to share with an initial value 'DEBUG' => 1, }; bless $self, $class; return $self; } # my ($class, $params) = $@; # return bless {} => $class; sub debug { my $self = shift; # optional boilerplate to keep track who called us and from where: my $parent = (caller(1))[3]; if( ! defined($parent) ){ $parent = 'main' } my $whoami = ( caller(0) )[3]; # optional parameter for setting the $DEBUG to a new value # if this new-value is absent the we just return current value of $DEBUG my $newvalue = shift; if( defined $newvalue ){ warn "$whoami (via $parent) : modifying DEBUG from ".$self->{'DEBUG'}." to $newvalue"; $self->{'DEBUG'} = $newvalue } return $self->{'DEBUG'} } 1;