Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Global symbol "%Properties" requires explicit package name (http://www.velocityreviews.com/forums/t907258-global-symbol-properties-requires-explicit-package-name.html)

mike 04-29-2008 08:55 AM

Global symbol "%Properties" requires explicit package name
 
Hi,

I have declared my %Properties but I get the following when I execute:

Global symbol "%Properties" requires explicit package name at test.pl
line 62.
Global symbol "%Properties" requires explicit package name at test.pl
line 67.
Global symbol "%Properties" requires explicit package name at test.pl
line 69.
Global symbol "%Properties" requires explicit package name at test.pl
line 71.
Global symbol "%Properties" requires explicit package name at test.pl
line 72.
Global symbol "%Properties" requires explicit package name at test.pl
line 73.

I have noted the lines in the code below.

Do I have to make some declaration within the sub?

cheers,

//mike


************************************************** *********************************************
use strict;
use warnings;

my $verbose = 0;
my $info = "[INFO] :";
my $error = "[ERROR]:";

my $configFile;
####################### Subroutines #######################

sub useage (){
print "Useage: perl rdeploy [ -file <config.dat path> ]\n";
exit 1;

}

sub readConfig {

print "Reading configuration data ...\n";
open FILE, "$configFile" or die "$error Could not open file
$configFile:$! ";
my %props = ();
while (<FILE>) {

s/\s+$//;# Remove all \r, \n, ^M from end of line
next if (/^$/);# ignore null lines
next if (/^\s*#/); # ignore comment line.
my ($config_name,$config_val)=split(/\s*=\s*/, $_,2);# Split the
line
$props{$config_name}=$config_val;
$verbose && print "$config_name\n";
}

close FILE;
return %props;

}


sub deploy {

my ($domain,$ear,$port) = @_;
#exit 1;

print "Make sure sailfin is started ...\n";

62: my @startargs = ($Properties{asadminexecutable},
'start-domain',
$domain);
system(@startargs) == 0 or die "system @startargs failed: $?";

67:print "Deploying $ear on $domain on HOST: $Properties{host} ....
\n";

69:my @deployargs = ($Properties{asadminexecutable},
'deploy',
71: "--user=$Properties{user}",
72: "--passwordfile=$Properties{passwordfile}",
73: "--host=$Properties{host}",
"--port=$port",
"$ear");

system(@deployargs) == 0 or die "system @deployargs failed: $?";
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}

}



#################################### Start Main
#######################################

# Checking arguments #

my $arg = @ARGV;
if ($arg > 0){
if($ARGV[0] =~ /-file/i){
$configFile=$ARGV[1];
}else{
&useage();
}
}else{
print "Using default config.dat in current in same directory as this
script!\n";
$configFile="config.dat";
}

my %Properties = &readConfig();


#Check that password file exists
print "Checking for passwordfile ...\n";
my $file = $Properties{passwordfile};
if(! -f $file ){
print "$error password file, $file, does not exist!";
exit 1;
}

#Deploy on both domains
deploy($Properties{domain1},$Properties{port1},
$Properties{frontenddeployunit});
deploy($Properties{domain2},$Properties{port2},
$Properties{backenddeployunit});

Bjoern Hoehrmann 04-29-2008 09:06 AM

Re: Global symbol "%Properties" requires explicit package name
 
* mike wrote in comp.lang.perl.misc:
>I have declared my %Properties but I get the following when I execute:
>
>Global symbol "%Properties" requires explicit package name at test.pl
>line 62.


>Do I have to make some declaration within the sub?


When checking whether your variables have been declared prior to their
use, perl checks how they occur in the source code, it ignores how the
program would be executed. You have to declare %Properties before any
use of it can be seen in the source code.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

Martijn Lievaart 04-29-2008 08:52 PM

Re: Global symbol "%Properties" requires explicit package name
 
On Tue, 29 Apr 2008 01:55:44 -0700, mike wrote:

> Hi,
>
> I have declared my %Properties but I get the following when I execute:
>
> Global symbol "%Properties" requires explicit package name at test.pl
> line 62.


A 'my' variable is in scope from the point of definition to the end of
the enclosing block. You're using the variable before it is defined. Just
move the definition to the top of the program.

HTH,
M4

Dr.Ruud 04-30-2008 08:20 AM

Re: Global symbol "%Properties" requires explicit package name
 
mike schreef:

> I have declared my %Properties but I get the following when I execute:
>
> Global symbol "%Properties" requires explicit package name at test.pl
> line 62.


You are using %Properties inside deploy(). But it is declared later.
You could move the "my %Properties" further up, but I would pass a
hash-refererence to deploy().
Or are there specifc reasons (like security) to not give deploy the full
%Properties?

readConfig() now returns a list, I would change that to a (scalar
containing a) hashref.

--
Affijn, Ruud

"Gewoon is een tijger."



All times are GMT. The time now is 03:41 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.