Date: 19 Sep 2001 13:00:51 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Global variables
Message-Id: <slrn9qh5jt.822.damian@puma.qimr.edu.au>

On Wed, 19 Sep 2001 10:09:05 +0200, Philippe PERRIN said:
>Hi
>
>I have a script.pl file, where I use a global variable :
>use strict;
>my %hash;
>
>In this .pl file, I use some .pm files of my own. How can I make these
>.pm modules access the %hash variable, defined in the .pl script ?
>

By declaring the hash with my(), you are making it lexical, and not
accessible from other file/package scopes. You need to either declare
it with an explicit package name:

	%main::hash = ();

or, with recent perls, use our():

	our %hash;

and in either case, then refer to it from other packages as:

	$main::hash{'foo'} = 'bar';

That is, assuming you declare package namespaces in your modules :-).

Cheers,
Damian
-- 
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/}  __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub


