I have a question, I need help here where I created this module to use in all my Perl scripts. It can be used first by
use ErrorModule;
and if I need to get a specific error for a particular script, I can call this subroutine “ app_error” inside the module like this:
&app_error("test.txt","File Name that created this error: test_mod.pl" +);

What I can’t understand is, why this module only works from the command prompt and not when I run the scripts from the browser. The Module is installed in c:/Perl/lib/
Please someone since I can get any answer anywhere.
Thanks a lot!!!!
Here is the module installed in c:/Perl/lib/
#!C:\perl\bin\perl.exe package ErrorModule; # The code in the BEGIN block will be executed very early # on, even before the rest of this script is parsed. BEGIN { # Use the CGI::Carp module and import the carpout() function. use CGI::Carp qw(carpout); #Send warnings and die messages to the browser. carpout(STDOUT); } use 5.008004; use strict; use warnings; #use CGI::Carp qw(carpout); use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); require Exporter; our @ISA = qw(Exporter); # 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. # This allows declaration use ErrorMod ':all'; # If you do not need this, moving things directly into @EXPORT or @EXP +ORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT = qw( app_error ); our $VERSION = '0.01'; our $localtime = localtime; #The Cwd module retrives the current working directory. #The safest way to get the current working directory is with #the cwd() function. This funstion is guaranteed to work on ALL #operating systems and should be used in most cases. use Cwd; our $dir = cwd(); # Set up error log file my $log_file = "error_log.txt"; open(LOG, ">>$dir/$log_file") or die "Unable to append to error log: $ +!"; carpout(*LOG); ##### ***subroutine who print in Appplication Specific Error*** sub app_error{ my $log_app = $_[0]; my @data = $_[1]; #Make sure that the filename doesn't have spaces or extensions like ex +e or bat on it, #otherwise it will create file as app_log.txt instead. unless($log_app=~/^[a-zA-Z_]+\.(?!bat$|exe$)[a-zA-Z_]{3}$/gi) { $log_app="app_log.txt" } open(LOGAPP, ">>$dir/$log_app") or die "Unable to append to $log_app: $!"; print LOGAPP "[$localtime] $log_app : @data $!\n"; carpout(*LOGAPP); close LOGAPP or die "Cannot close log file:: $log_app : $!\n"; } 1; __END__


And here is a test script
#!/perl/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use CGI qw(-oldstyle_urls :standard); use ErrorModule; my $empty; # case 1 my $test = "test"; print header(); print "<br> This is a test<br>"; print $test; print $empty; print "<form action=madetofail.pl method=get>"; print "<input type=text><input type=submit value=go>"; &app_error("test.txt","File Name that created this error: test_mod.pl" +); print "after" # left ; out to fail and to log error by ErrorModule

Tks, again!

In reply to Error Module not working in Browser, 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.