Global symbol "%Properties" requires explicit package name

Discussion in 'Perl Misc' started by mike, Apr 29, 2008.

  1. mike

    mike Guest

    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});
    mike, Apr 29, 2008
    #1
    1. Advertising

  2. * 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: · 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/
    Bjoern Hoehrmann, Apr 29, 2008
    #2
    1. Advertising

  3. 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
    Martijn Lievaart, Apr 29, 2008
    #3
  4. mike

    Dr.Ruud Guest

    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."
    Dr.Ruud, Apr 30, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xxx
    Replies:
    0
    Views:
    824
  2. snowdog
    Replies:
    2
    Views:
    385
    Joe Smith
    Nov 7, 2004
  3. sam

    requires explicit package name

    sam, Jan 6, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    243
    Tad McClellan
    Jan 12, 2005
  4. Replies:
    5
    Views:
    1,017
    Sherm Pendley
    Jan 28, 2005
  5. Replies:
    6
    Views:
    1,768
Loading...

Share This Page