On Jul 15, Hamish Whittal said: >1) Keep a central 'repository' (a hash) of all errors that can be >generated in all the different modules and pass the error to a function >that decides what error to run.
That sounds like a good idea. >package Common; > >sub ERRORSTRING { > >########################################################################## ># Error messages for this module ># Potentially FATAL ERRORS < 1000, WARNINGS > 1000 ># >%err = { > 1 => "(1) Cannot open error file for logging warnings and errors.", > 2 => "(2) Device did not respond to SNMP request.", > 3 => "(3) Could not create connection to the database. Fatal error - >giving up!", > 1001 => "(1001) Cannot open hosts file. It may not present, or perhaps >it needs to be \"re-imorted\" from NNM. In the latter case, please read >the documentation on how to remiport the hosts file from NNM", > 1002 => "(1002) Warning 1002", > 1003 => "(1003) Warning 1003" >}; First of all, you want ()'s around your hash defintion, not {}'s. If you can't tell the two apart, you want PARENTHESES, not BRACES. Get a better font if they look the same to you. Second, you're defining this (big) hash EVER time the function is called! Don't do that! Place the hash OUTSIDE the function, so it gets created when the module is used, and never again. And just because multiple files use the module doesn't mean the hash will get created many times. Perl only EXECUTES the contents of a module once. >my ($this, $error) = @_; >my $type; >($DAY, $MONTH, $YEAR) = (localtime)[3,4,5]; >$YEAR += 1900; >$MONTH += 1; > >$type = qq(ERROR) ? $error < 1000 : qq(WARNING); You have this inverted a bit. It should be $type = $error < 1000 : qq(ERROR) : qq(WARNING); The general syntax is CONDITION ? TRUE : FALSE > > my $curr_err = qq($DAY/$MONTH/$YEAR $type [$this] : $err{$error}\n); > return $curr_err; >} -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]