Well thankyou all for the replies. (This must be one of the best lists I subscribe to.)
Now, why I wanted to run the code each time I called the module... I am wanting to do error checking within my code. I am experimenting with the best ways to do this. 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. 2) Place errors particular to the module within the module and get a hash to be generated whenever I make a call to the module... 3) Others, I'm open to suggestions of better ways of doing this...but hurry, suggestions are limited ;-) At the mo, I have opted for 1), so, here is my code: 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" }; ########################################################################## my ($this, $error) = @_; my $type; ($DAY, $MONTH, $YEAR) = (localtime)[3,4,5]; $YEAR += 1900; $MONTH += 1; $type = qq(ERROR) ? $error < 1000 : qq(WARNING); my $curr_err = qq($DAY/$MONTH/$YEAR $type [$this] : $err{$error}\n); return $curr_err; } 1; Now, I have modules A.pm, B.pm, C.pm as well as a main program Main.pl. I include the Common.pm at the head of each module and the Main.pl. I can then call the ERRORSTRING like so: $errorStr = ERRORSTRING((caller(0)[3]),1001); Then, assuming I've opened a file for errors, I can print the error to the file. Only problem is that I need to keep opening and closing the text file for errors. I'm concerned about speed, and this slowing things down considerably. Sorry bout the long posting, but if anyone has other ways of dealing with error reporting I'd be happy to hear them. Thanks in advance, H On Mon, 2003-07-14 at 15:43, Jeff 'japhy' Pinyan wrote: > On Jul 14, Hamish Whittal said: > > >Anyone know whether or how I can initialise code when calling any of the > >subroutines within a module? > >I don't necessarily want to call the module personally, I would like it > >to be called when I call any of the subroutines. > > There are builtin modules like SelfLoader that allow you to use a module, > but the functions won't be compiled until you call them. > > Or, if you're going to call the functions in the module with their FULL > package name (like MyModule::foobar()), then you can use an AUTOLOAD > function to catch the function call, include the module, and then call the > function in the module. > > The first is MUCH easier than the second. I'm curious why you need to do > this, though. -- You are not defined by what loves you, but what you love - Nicholas Cage (Adaptation, 2003) --- Hamish Whittal QED Technologies cc +27 82 803 5533 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]