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

require() does not behave aas documented

Thread Next
From:
Steve Hay
Date:
September 15, 2003 02:53
Subject:
require() does not behave aas documented
Message ID:
3F658C9C.1060500@uk.radan.com
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:

    test.pl
    =======
    eval { require Foo };
    print "require() failed\n" if $@;
    foreach (keys %INC) {
        print "$_ => $INC{$_}\n";
    }

    Foo.pm
    ======
    package Foo;
    sub
        print "Oops!\n";
    }
    1;

This outputs:

    require() failed
    Foo.pm => Foo.pm

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About