Global symbol "%Properties" requires explicit package name

M

mike

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});
 
B

Bjoern Hoehrmann

* 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.
 
M

Martijn Lievaart

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
 
D

Dr.Ruud

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,930
Messages
2,570,072
Members
46,521
Latest member
JamieCooch

Latest Threads

Top