-----Original Message----- >From: Beginner <[EMAIL PROTECTED]> >Sent: Mar 6, 2007 11:53 PM >To: beginners@perl.org >Subject: Centralised variables - different issue > >Hi, > >Following on from the earlier thread about storing common code in a >central file, I have hit a problem when trying to do something >similar. > >I have been toying with SOAP. There seems to be a number of ways to >create SOAP services and I opted for one of the examples at >guide.soaplite.com. > >So my code looks a bit like this at the moment: > >========== test.pl ========== >#!/usr/bin/perl > >use strict; >use warnings; >use Mymodule qw($server); >use SOAP::Transport::HTTP; > >SOAP::Transport::HTTP::CGI > ->dispatch_to('Test') > ->handle; > >package Test; # Is this the problem? > >sub hi { > return "Hello World"; >} > >sub bye { > return "It's all over"; >} > >sub Mysub { > return "Variable \$server=$server"; >} > >===================== > >Mymodule looks like this: > >=========== Mymodules.pm ========== >package MyModule; > >require Exporter; >use strict; >use warnings; >use SOAP::Lite; > >our @ISA = qw(Exporter); >our @EXPORT = qw($server $name); >our $VERSION = 1.00; > >our $server = 'localhost.somedomain.com'; >our $name = 'Smithe'; > >1; >========================== > >When I run perl -c test.pl I get >Global symbol "$server" requires explicit package name at test.pl >line 25. >test.pl had compilation errors. > >and the same apepars in the server logs. There is a scoping issue >here but I can't see where it comes from. > >Does anyone have any ideas? >Thanx,
Hello, I found at least 4 things which are may not correct or not good. 1) use Mymodule qw($server); Since you've exported global variable $server in the MyModule.pm explicitly,so here you don't need to imported them into current script by qw(..) again.It can just write: use MyModule; 2) package MyModule; Here you declare the package name as "MyModule",but in the main script you "use Mymodule".It can't work at all. 3) package Test; Please don't name the package name as "Test" since Test.pm is already a common package on the CPAN. 4) use MyModule; package Test; These wouldn't import the global variable in the MyModule.pm into your package "Test".I think the correct way is: package MyTest; use MyModule; (change the statements' order and rename your package name.) After adjusting all these above,I think your program would work. Hope this useful. -- http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/