title: Undefined subroutine &package::subroutine called at line <of script>
body: <p>I am debugging this script at work - the boss says that is used to work on Solaris, but since they switched over to linux, it stopped working. I had to rewrite it with strict and warnings . 
  When I run it I get error: </p>
  
  <pre><code>Undefined subroutine &amp;Logging::openLog called at /path/to/script line 27
  </code></pre>
  
  <p>here is script (well part of it)   </p>
  
  <pre><code> 1  #!/usr/local/bin/perl
   2
   3  unshift @INC, "/production/fo/lib";
   4  use strict;
   5  use warnings;
   6  use Sys::Hostname;
   7  use Getopt::Long qw(:config bundling auto_version);
   8  use File::Path;
   9
  10  require "dbconfig2.pl";
  11  require "logging2.pl";
  12  require "hpov.pl";
  13
  14  # global variables
  15  my $parseDate   = "";
  16  my @fileList    = "";
  17  my @transList   = "";
  18  my $mLogDate    = "";
  19  my $lHost                       = hostname;
  20  my $corefiles_dir="/production/log/corefiles";
  21  my $default_Threshold=90;
  22
  23  # do stuff
  24
  25  parseOptions();
  26  Dbconfig::readconfigFile("$config");
  27  Logging::openLog("$Dbconfig::prefs{logFile}","overwrite");
  28  # msglog actions  TODO logs, compress only, data files
  29          my $check_shdw=`ls -l /etc/motd | awk '{print \$11}' | grep 'motd.shdw'`; #Check if hostname is shadow
  30          $check_shdw =~ y/\n//d; #remove new line if any
  31  if ( $check_shdw eq "motd.shdw" )
  32  {
  33          Logging::printLog("INFO","Enviroment is Shadow, triggering core files compressing");
  34          if (is_folder_empty($corefiles_dir)) {
  35              print "Corefile Directory is EMPTY......! \n";
  36          }
  37          else {
  38          gzip_corefiles() ; #Execute compress core files
  39          }
  40  }
  41
  </code></pre>
  
  <p>The script uses require statements to I guess call upon the routines that the script creator built. 
  For the purpsoe of this script - the dbconfig just slurps in a config file and breaks them down into values. 
  like the "$Dbconfig::prefs{logFile}" equals a logfile location  /prod/logs/script.log - that's it. </p>
  
  <pre><code>#!/usr/local/bin/perl
  
  package Dbconfig;
  #use warnings;
  use DBI;
  use DBD::Oracle;
  
  %prefs          = "";
  @$dbPrefs       = "";
  $raiseError     = 0;
  %startupItem    = "";
  
  # readconfigFile(file) - read in a configuration file.
  sub readconfigFile { 
      my $file = shift;
      if ( ! -e $file ) {
          $errorTxt   = "Error: $file does not exist.\n";
          $raiseError = 1;
      }
  # read in the cfg variables
     open(CFGFILE,"&lt;","$file") or die "Cannot open $file for reading: $!\n";
     while(&lt;CFGFILE&gt;) {
      chomp;    # kill newlines
      s/#.*//;  # ignore comments
      s/^\s+//; # ignore leading whitespace
      s/\s+$//; # ignore trailing whitespace
      next unless length;
      my($var,$value) = split(/\s*=\s*/, $_, 2);
      $prefs{$var} = $value;
     }
     close(CFGFILE);
  }
  </code></pre>
  
  <p>Then there is this logging package. In line 27 of the script (where the error comes in) i see an "overwrite" invocation, but don't see anything referenceing overwrite in the logging.pl package - but not really sure if it matters. the parent script does not seem to write to any log file. I am not even  sure if the filehandle LOGFILE is gtting created. </p>
  
  <pre><code>#!/usr/local/bin/perl
  
   package Logging;
  
  use File::Copy;
  use warnings;
  use strict; 
  
  my $timestamp = "";
  my $filestamp = "";
  
  # openLog(logfile name) - opens a log file
  sub openLog {
      my $file   = shift;
      my $rotate = shift;
   # force a rotation if it exists.
      if ( -e $file &amp;&amp; $rotate eq "rotate" ) {
          print "Warning: $file exists.  Rotating.\n";
          rotateLog($file);
      }
      getTime(); 
      open(LOGFILE,"&gt;","$file") or warn "Error: Cannot open $file for writing: $!\n";
      print LOGFILE "[$timestamp] - Normal - Opening log for $file.\n"; 
  }
  # rotateLog(log file) - rotate a log.
  sub rotateLog {
      my $file = shift;
      getTime();
      openLog("$file");
      print LOGFILE "[$timestamp] - Warning - Rotating $file to $file.$filestamp.log";
      closeLog($file);
      move($file,$file-"$filestamp.log");
      openLog($file);
  }
  time() - grab timestamp for the log.
  sub getTime {
      undef $timestamp;
      undef $filestamp;
      ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time))[0,1,2,3,4,5];
      $sec    = sprintf("%02d",$sec);
      $min    = sprintf("%02d",$min);
      $hour   = sprintf("%02d",$hour);
      $mday   = sprintf("%02d",$mday);
      $year   = sprintf("%04d",$year +1900);
      $mon    = sprintf("%02d",$mon +1);
      $timestamp  = "$mon-$mday-$year $hour:$min:$sec";
      $filestamp  = "$year$mon$mday$hour$min$sec";
  }
  </code></pre>
  
  <p>just wondering - is there a problem with logging.pl calling something from dbconfig.pl in line 27?  Like can one module call a value fron another module?  besides using strict and warnings, and alot of print statements I do not know what my next debugging
   step is.  I have not idea how to check and see that the LOGFILE filehandle is getting created - if it does not error out, I can only suppose that it is. Like is there something extra I have to do to get the modules talking to each other?</p>
  
  <p>I am not a scripting king - just the only guy in my row who can even begin to understand this stuff. </p>