Re: share a variable between files

2014-10-09 Thread Shawn H Corey
On Wed, 8 Oct 2014 21:36:06 +0200 Hans Ginzel wrote: > I want to use one global hash variable for options or configuration > variables like verbose, debug. I don't want to pass them to each > function or to almost each object. package main; our %Opts = ( verbose => 0, debug => 0. ); # yo

Re: share a variable between files

2014-10-09 Thread Hans Ginzel
On Thu, Oct 09, 2014 at 03:50:02AM +1300, Kent Fredric wrote: First, what are you trying to acheive. Global variables are rarely a good idea, as is sharing variables between files. So the question is, why are you trying to share a variable between files using globals? My suggestion is

Re: share a variable between files

2014-10-08 Thread Kent Fredric
On 9 October 2014 08:36, Hans Ginzel wrote: > I want to use one global hash variable for options or configuration > variables > like verbose, debug. I don't want to pass them to each function > or to almost each object. > Indeed, Jim Gibson explains you can simply declare "our" in both files an

Re: share a variable between files

2014-10-08 Thread Jim Gibson
The ‘our’ statement associates a simple name with a package global variable in the current package. Therefore, if you want to make $var in file b.pl mean the package global variable $var in package a ($a:var), just put ‘our $var;’ after the ‘package a;’ statement in file b.pl (see below). On Oc

Re: share a variable between files

2014-10-08 Thread Kent Fredric
On 9 October 2014 03:35, Hans Ginzel wrote: > Hello! > > Let's consider following strip-down example: > > # file a.pl > use strict; > package a; > our $var=1; > warn "var=$var"; > > # file b.pl > use strict; > #no strict qw/vars/; > require 'b.pl'; > package a; > warn "var=$var"; > > How to get r