Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
package NewError; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; @ISA = qw(Exporter AutoLoader); # Items to export into callers namespace by default. Note: do not expo +rt # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT = qw(log_error std_log_error); #$VERSION = sprintf "%d.%03d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/; $VERSION = '0.01'; # Define global variables use vars qw( $curr_dir $work_file $log_file $std_log_file); #--------------------------------------------------------------------- +------------ # Grab the current directory from $0. The following regular expressio +n # looks for 'CURR_DIR\xxxxx.xxx' or 'CURR_DIR/xxxxx.xxx'. Place it in # the BEGIN block so we can use it to include modules #--------------------------------------------------------------------- +------------ BEGIN { $0 =~ '(.*[\\\/])\w+\.\w+$'; $curr_dir = $1 || "./"; } sub log_error{ # Set up error log file $log_file = "error_log.txt"; use CGI::Carp qw(carpout); open(LOG, ">>${curr_dir}${log_file}") or die "Unable to append to error log: $!"; carpout(*LOG); } ##### End Sub log_error sub std_log_error{ #This will log general errors generated as example by user interaction my @data = @_; $std_log_file = "error_log_std.txt"; my ( $year, $mon, $day, $hr, $min, $sec) = Today_and_Now(); my $timestamp = sprintf "%02d-%02d-%02d:%02d:%02d:%02d ", $mon, $day, +($year - 2000), $hr, $min, $sec; open(LOG_FILE, ">>${curr_dir}${std_log_file}") or die "Unable to append to error log: $!"; print LOG_FILE $timestamp, @data, "\n"; close( LOG_FILE ); } #### End Sub std_log_error 1; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Module Help
by holli (Abbot) on Dec 30, 2005 at 17:29 UTC | |
by Anonymous Monk on Dec 30, 2005 at 18:37 UTC | |
|
Re:Module Help
by tinita (Parson) on Dec 30, 2005 at 20:04 UTC | |
|
Re: Module Help
by choedebeck (Beadle) on Dec 30, 2005 at 21:55 UTC | |
|
Re: Module Help
by InfiniteSilence (Curate) on Dec 30, 2005 at 18:26 UTC | |
by Anonymous Monk on Dec 30, 2005 at 18:38 UTC |