Redefining routines 
Author Message
 Redefining routines

Hi

I have 5 modules, A-E, where

A require B
B require C,D,E
C require E
D require E

Should the require-state in C and D be left out?

If I have an extra module F which is required by all the modules,
should this only be explictly required in A?

Thanks for any answer

Morten Simonsen

P.S. If use require statement everywhere, I get "redefining
subroutine"-warning.



Thu, 25 Jan 2001 03:00:00 GMT  
 Redefining routines

Quote:
>Hi

>I have 5 modules, A-E, where

>A require B
>B require C,D,E
>C require E
>D require E

>Should the require-state in C and D be left out?

>If I have an extra module F which is required by all the modules,
>should this only be explictly required in A?

Since require always checks if the module is already loaded, it never
does any harm to require modules more than once.

If you *know* that C will only ever be used in conjunction with B, the
require E; in module C is indeed redundant.   But it's better practice
to avoid making assumptions like that.   Then module C will be more
easily reusable.

Quote:
>P.S. If use require statement everywhere, I get "redefining
>subroutine"-warning.

Since require only loads a particular piece of code once, this warning
must be being caused by something else.   Perhaps some two of your
modules define a subroutine of the same name in the same package.

Mike Guy



Thu, 25 Jan 2001 03:00:00 GMT  
 Redefining routines

Quote:


>>P.S. If use require statement everywhere, I get "redefining
>>subroutine"-warning.
> Since require only loads a particular piece of code once, this warning
> must be being caused by something else.   Perhaps some two of your
> modules define a subroutine of the same name in the same package.

I eventually found the error. It was caused by a mistyping in the
require-statement, like this:

require "$cond::PATH{'DB'}misc.pm";

instead of:

require "$conf::PATH{'DB'}misc.pm";

$conf::PATH{'DB'} contained the absolute path of misc.pm.
$cond::PATH{'DB'} contained nothing.

Because misc.pm was in the same directory as the file with the
mistyped require-statement, no error was discovered at this
moment. But apparently the same module were viewed as two different
ones, and then the warning came up. I am right? This means that a
relative and a absolute reference to a file makes two different files?

Morten Simonsen



Tue, 30 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Error : calling sub routine inside another sub routine

2. How to determine calling routine from a called routine

3. Redefined subroutines using mod_perl

4. Redefining MacPerl 'novice'

5. Error - Subroutine new redefined

6. Redefining \w and \b possible?

7. Redefining formats (ARG!)

8. redefining a sub

9. Subroutine exec redefined warning with perl 5.12.2

10. problem redefining a function

11. redefining subroutine, perldiag vs. other

12. Subroutine OK redefined

 

 
Powered by phpBB® Forum Software