On Thu, 14 Jun 2001, Peter Jay Salzman wrote:

> dear all,
> 
> i'm trying to figure out how a perl module accesses a global variable.
> below i show listings for the module (Hello.pm) and the program
> (testmodule.pl).  testmodule defines a global variable which i'd like
> to know how to access from within Hello.pm.
> 
> anyone know how to do this?

This seems like a bad idea, but in the spirit of "there is more than one
way to do it" you could try...

> 
> thanks!
> pete
> 
> 
> 
> Hello.pm:
> 
>        package Hello;
>        require Exporter;          # } These set up an import
>        @ISA = qw(Exporter);       # } method, called implicitly
>        @EXPORT = qw( say_hello ); # } by use().
>        
>        sub say_hello {
>           print "Hello, world!\n";
>           print $globalvariable . "\n";

 print "${::globalvariable}\n";

>        }
>        return 1;
> 
> 
> 
> testmodule.pl:
> 
>       #!/usr/bin/perl -w
>       use diagnostics;
>       use Hello;
>       
>       my $globalvariable = "hello world";

 $globalvariable = "hello world";

>       
>       print "using scope specifier:\n";
>       Hello::say_hello();
>       
>       print "now without scope specifier:\n";
>       say_hello();
> 

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[EMAIL PROTECTED]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------

Reply via email to