Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Error : requires explicit package name

Expand Messages
  • Durai
    Hi, Thanks for your help. I was very confusing for this problem. Regs, Durai. ... From: franki To: perl-beginner@yahoogroups.com Sent: Friday, April 30, 2004
    Message 1 of 3 , Apr 30, 2004
    • 0 Attachment
      Hi,

      Thanks for your help. I was very confusing for this problem.

      Regs,
      Durai.
      ----- Original Message -----
      From: franki
      To: perl-beginner@yahoogroups.com
      Sent: Friday, April 30, 2004 4:33 PM
      Subject: Re: [PBML] Error : requires explicit package name


      Durai wrote:
      > Hi Experts,
      >
      > I have the following problem when I perl program.
      >
      > $ perl runtest.pl
      > Global symbol "$PROD_TESTS" requires explicit package name at
      > common_functions.pl line 13.
      > Global symbol "$LOG_DIR" requires explicit package name at
      > common_functions.pl line 16.
      > Global symbol "$TOTAL_TEST_LOG" requires explicit package name at
      > common_functions.pl line 21.
      > Global symbol "$TOTAL_TEST_LOG" requires explicit package name at
      > common_functions.pl line 21.
      > Global symbol "$PROD_TESTS" requires explicit package name at
      > common_functions.pl line 26.
      > Compilation failed in require at runtest.pl line 6.
      >
      > runtest.pl
      > -----------
      >
      > #!/opt/perl/bin/perl -w
      > use strict;
      >
      > require "test_init.pl" or die("Can't require test_init.pl");
      > require "common_functions.pl" or die("Can't require common_functions.pl");
      >
      > test_init.pl
      > ------------
      > #!/opt/perl/bin/perl -w
      > use strict;
      > my $LOG_DIR="/home/durai/testlogs";
      > my $PROD_NAME="ixAnt";
      > my $TOTAL_TEST_LOG="$LOG_DIR/$PROD_NAME/totaltestresult.log";
      > $LOG_DIR="$LOG_DIR/$PROD_NAME";
      > my $PROD_DIR="/home/durai/testautomation/$PROD_NAME";
      > my $PROD_TESTS="$PROD_DIR/tests";
      >
      > common_functions.pl file uses the variables which are in test_init.pl file.
      >
      > What is the wrong?
      >
      > Any help much appreciated.
      >
      > Regs,
      > Durai.


      Yup, 'my' won't work like that when used from a required file..

      You have some options for just getting it working, or doing it properly..

      I'll start with just getting it going.....

      - use 'our' instead of 'my'.
      - turn off strictures .

      neither of those are good ideas....

      better that you put the variables inside a sub, and then call the sub
      from inside the main program..
      for example, in test_init.pl

      sub config {
      my $var1 = 'foo';
      my $var2 = 'bar';

      return ($var1, $var2);
      }



      Then in runtest.pl:

      my ($var1, $var2) = config();

      That should work...

      You could go further and give the config sub its own namespace and
      export the config vars, thats probably the best easy answer...

      Randal may well tell you that you should use config::tiny or one of the
      other such modules, and he would probably be right... if you have that
      option.. :-)


      rgds

      Franki



      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html



      ------------------------------------------------------------------------------
      Yahoo! Groups Links

      a.. To visit your group on the web, go to:
      http://groups.yahoo.com/group/perl-beginner/

      b.. To unsubscribe from this group, send an email to:
      perl-beginner-unsubscribe@yahoogroups.com

      c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.665 / Virus Database: 428 - Release Date: 4/21/2004

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.