Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Recursive use causes subroutine redefinition

by ysth (Canon)
on Sep 08, 2004 at 08:49 UTC ( #389301=note: print w/replies, xml ) Need Help??

in reply to Recursive use causes subroutine redefinition

Nothing is wrong with your recursive uses; the problem is that you are also loading as a script, bypassing the multiple load checks that exist for require or use. The same thing happens without the recursion:
$ cat> package Baz; use strict; use warnings; use Baz; sub baz { } 1; $ perl Subroutine baz redefined at line 5.
If you are going to use the same file both via use or require and as a main script or via do, you should manually put a "BEGIN { $INC{} ||= __FILE__ }" in before any possible use/require.

Replies are listed 'Best First'.
Re^2: Recursive use causes subroutine redefinition
by prowler (Friar) on Sep 08, 2004 at 14:38 UTC

    So the use/require check is based on whether the module has been loaded by use/require before, and doesn't count the explicit loading of the module at the command line? Thanks for the info - that explains why no warnings were output when the script was actually in use then.

    As I hinted at in the original message (but didn't make very clear) the reason that I noticed (and was annoyed by) those warnings was that Eclipse (with the Perl plugin) does compile time checking of code and provides a list of the errors/warnings it can find - this was being cluttered up by those warnings.

     - Spelling is a demanding task that requies you full attention.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://389301]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2020-12-03 05:11 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (50 votes). Check out past polls.