develooper Front page | perl.perl5.porters | Postings from September 2003

require() does not behave aas documented

Thread Next
Steve Hay
September 15, 2003 02:53
require() does not behave aas documented
Message ID:
The perlfunc documentation for require() gives some pseudo-code that 
suggests that the %INC entry for a require()'d file will be removed if 
the file couldn't be loaded.  The following test script & module (with a 
deliberate error in the latter) shows that this is not the case:
    eval { require Foo };
    print "require() failed\n" if $@;
    foreach (keys %INC) {
        print "$_ => $INC{$_}\n";
    package Foo;
        print "Oops!\n";

This outputs:

    require() failed =>

Ideally it would be nice to have this fixed to work as documented.  (I'm 
using some code that examines %INC to see if a file is loaded and then 
loads it if it isn't.  It keeps crashing because entries are left in 
%INC by previous, failed, attempts at loading the file, fooling it into 
thinking that the file is loaded when it isn't.)

Failing that, the documentation should be changed to more accurately 
represent what require() actually does.

- Steve

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About