perlguyjoe has asked for the wisdom of the Perl Monks concerning the following question:
Here is the main script:# ./path.pl Undefined subroutine &dbug::dbug called at ./path.pl line 56.
And here is the module:#!/usr/bin/perl use lib qw(../lib/); use warnings; use strict; use Proc::Daemon; use Proc::PID::File; use File::Copy; use DBI; use XML::Simple; use POSIX; use dbug qw(dbug); my $path = "/opt/homeforscript"; my $hopper = "$path/hopper"; my $deliveryDir = "$path/hopper2"; my $log = "/var/log/script.log"; my $timestamp = POSIX::strftime("%m/%d/%Y %H:%M:%S", localtime); my $dbh; defined(my $pid = fork) or die "Cannot fork: $!\n"; exit if $pid; $dbh = dbConnect() or exit -1; dbug("Fork", "[$$ DB] Connected\n"); open (LOG, '>>', $log) or die("Cannot open Log"); print LOG "Log Opened\n"; for (;;) { #Open the hopper opendir (HOPPER, $hopper) or die $!; # And look for Files checkHopper(); sleep 1; } ############################ # Sub's # ############################ sub dbConnect { #print LOG "$timestamp - [Trying to Connect to DB]\n"; dbug("DB", "DBI CONNECTED"); print LOG "$timestamp - [DBI CONNECTED]\n"; eval { $dbh = DBI->connect('dbi:mysql:DBNAM','DBUSER','DBPASS +WD')or print LOG "Connection Error: $DBI::errstr\n"; }; return $dbh; } sub checkHopper { #Read a list of files in hopper if (is_folder_empty($hopper)) { } else { while (defined(my $file = readdir(HOPPER))) { #open (LOG, '>>', $log) or die("Cannot open Log"); if ($file !~ /^\./) { dbug("INCOMMING", "Found file named $file in i +ncomming hopper\n"); #print LOG "$timestamp - Found file named $fi +le in incomming hopper\n"; move("$hopper/$file", "$deliveryDir/$file") or + print LOG "cannot move $hopper/$file to $deliveryDir/$file\n"; dbug("PROCESSING", "Moved $file from hopper fo +r processing \n"); #print LOG "$timestamp - Moved $file from hopp +er for processing \n"; my $sql = "select * from transfers"; my $sth = $dbh->prepare($sql); $sth->execute or die dbug("DB", "SQL Error: $D +BI::errstr\n"); dbug("DB", "Queried the Database\n"); if (my @row = $sth->fetchrow_array) { dbug("QUERY", "@row\n"); } } } } } sub is_folder_empty { my $dirname = shift; opendir(my $dh, $dirname) or die "Not a directory"; return scalar(grep { $_ ne "." && $_ ne ".." } readdir($dh)) == 0; }
#!/usr/bin/perl # $Id: dbug.pm $ package dbug; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(dbug); use strict; use warnings; use POSIX; my $timestamp = POSIX::strftime("%m/%d/%Y %H:%M:%S", localtime); sub pdebug { my $logDate = POSIX::strftime('%y%m%d', localtime(time)); my $component = shift; my $string = shift; my $logto = "/var/log/logfile.log.$logDate"; open (LOGGER, '>>', $logto) or die("Cannot open Log"); print LOGGER "$timestamp - [$component] $string"; close(LOGGER); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subroutine not seeing export from module
by roboticus (Chancellor) on Feb 08, 2014 at 15:37 UTC | |
by perlguyjoe (Novice) on Feb 08, 2014 at 15:45 UTC | |
|
Re: Subroutine not seeing export from module
by toolic (Bishop) on Feb 08, 2014 at 15:49 UTC | |
|
Re: Subroutine not seeing export from module
by BrowserUk (Patriarch) on Feb 08, 2014 at 15:38 UTC | |
|
Re: Subroutine not seeing export from module
by McA (Priest) on Feb 08, 2014 at 15:38 UTC |