As far as I know I am exporting it and declaring it as you can see:Software error: Undefined subroutine &main::data_log called at my_script.pl
#!/usr/bin/perl use strict; use warnings; use CGI qw(-oldstyle_urls :standard); use Time::Zone; use Date::Format; use Date::Parse; use CGI::Carp qw(fatalsToBrowser); use CGI qw(escapeHTML); use File::Basename; use Data::Dumper; use Digest::MD5 'md5_hex'; use Date::Calc qw( Today Today_and_Now Date_to_Days Add_Delta_Days ); use CGI::Session ( '-ip_match' ); use POSIX; use JSON; use HTML::Template; use lib '../MyLib'; # Add private library to path use Logger qw(data_log); # Load source at runtime my $q = new CGI; $| = 1; BEGIN { # Set log file my $log = 'log.log'; use CGI::Carp qw(carpout); # Send all warnings to the log_file open STDERR, '>>', $log; } # Load Main Template my $main_templ = HTML::Template->new(filename => '../../temp/main.tmpl +'); $ENV{'TZ'} = 'America/New_York'; #Logging to a file data_log('logger_error.txt', $ENV{'TZ'}); ...
#!/usr/bin/perl # # Logg.pm # # package MyLib::Logger; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw( data_log ); # Exported, if explicitly requested our $VERSION = '0.01'; sub data_log { my ($log_file, @data) = @_; my $log_fh; # Log data to file my $timestamp = '[' . localtime() . '] '; if ($log_file && ($log_file !~ /^STDOUT$/i)) { # Allow tee-ing of logfile to STDOUT and a file ('|tee -a log_file +.txt') if ($log_file !~ /^\|/) { $log_file = ">>${log_file}"; } open $log_fh, $log_file or warn "Can't open $log_file: $!"; print $log_fh $timestamp, @data, "\n"; close $log_fh; } else { print $timestamp, @data, "\n"; } return; } 1; # End of Logg.pm
In reply to Export not exporting from module by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |