http://qs1969.pair.com?node_id=129696


in reply to Re: Coding for two platforms in one Script
in thread Coding for two platforms in one Script

The problems with require are that for the Win32::EventLog module (at least) you get lots of 'undefined' errors (with and without -w) when the module is required (although it does continue to run, but makes examining the legitimate output of the script problematic). I also understand that I need to require in each BLOCK that uses functions from that module, well, if I don't I get more compilation errors! I get the impression that I'm incurring more overhead by doing so.

I was unsure about the import function - do I need to use that in every BLOCK that the require appears in?

Thanks for your (and everyone elses!) reply :-)

Pete

Replies are listed 'Best First'.
Re: Re: Re: Coding for two platforms in one Script
by perrin (Chancellor) on Dec 05, 2001 at 23:20 UTC
    You shouldn't get any errors when the module is required unless it has bugs. Are you talking about undefined variable errors, or are you using subroutines imported from the module during a use()?

    There is no need to require the module in each block. Just require it once. If you are using imported subs, you will need to import it once in each module that uses those subs.

    It's hard to understand why you're getting these errors, so maybe you should try to post a small example of some code that gives you errors when you use require.

      I finally worked out what was causing the 'undefined variable' errors, and have resolved them.

      The POD docs for Win32::EventLog imply that you can leave undefined variables which you don't want to use. This is true, from a functional perspective, but the module itself doesn't check that everything it's putting into a subroutine call is defined, hence the errors.

      So the solution (for this module) is to either define the variables in the Report call properly, or set them to null/zero. I've also found that I need to set the machine name in the new() call, otherwise it also generates an undefined error.

      You live and learn ;-)

      Pete