Hi Monks!
I am trying to create a module to use in all me Perl programs, but I can't get it to work, can someone take a look at it and give some advice and also how it should properly be called in my scripts.
Thanks a lot!
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__

In reply to Module Help by Anonymous Monk

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.