Hello again prestigious monks. I am stuck and I hope you can help. I have a simple perl module that I use to write logging info into a text file. I call this module from scripts that run as daemons along the way to log useful tidbits of info. I am stuck on this error though. Its like my subroutine in the main script doesn't see the sub exported by loading the module. As soon as the sub routing dbConnect tries to run the dbug() it bombs. Any insight is appreciated.
# ./path.pl Undefined subroutine &dbug::dbug called at ./path.pl line 56.
Here is the main script:
#!/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; }
And here is the module:
#!/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); }

In reply to Subroutine not seeing export from module by perlguyjoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.