Manipulating Perl include path
Jan. 1st, 2008 05:28 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I have a wee problem in a current project. My code uses the XML::Parser module, and it needs to be a recent version. So I've uploaded this to the server and am adding it to the include path with the help of a use lib in the normal sort of way.
Unfortunately, elsewhere on the server there seems to be an old version of the module, and it seems to be using this one in preference to my nice shiny new one.
Is there any way I can, at run-time, compel it to look for the module only in my preferred part of the include path? Maybe by monkeying with whatever environment variable it is that controls the said path?
I thought of renaming the version of the module that I uploaded, and using it under the new name, but that seems a bit drastic. But maybe it's not really.
Unfortunately, elsewhere on the server there seems to be an old version of the module, and it seems to be using this one in preference to my nice shiny new one.
Is there any way I can, at run-time, compel it to look for the module only in my preferred part of the include path? Maybe by monkeying with whatever environment variable it is that controls the said path?
I thought of renaming the version of the module that I uploaded, and using it under the new name, but that seems a bit drastic. But maybe it's not really.
no subject
Date: 2008-01-01 05:32 pm (UTC)no subject
Date: 2008-01-01 06:55 pm (UTC)no subject
Date: 2008-01-02 05:59 am (UTC)http://www.perlhowto.com/extending_the_library_path
no subject
Date: 2008-01-02 11:18 am (UTC)BEGIN {unshift @INC, "/directory/where/you/put/it"}
The unshift puts the new directory at the beginning of the list, so it'll find that one first.
Alternatively, you can invoke perl with the -I option, which adds to the beginning of @INC.
Or you can use lib like you are doing, which also adds the path to the start of the list. This is normally the best way if you just have a simple directory path to add.
So, why doesn't it work for you? Are you sure you are specifying the directory containing the XML directory, not the XML directory itself? It adds XML/Parser.pm to each directory in the path.
no subject
Date: 2008-01-02 11:25 am (UTC)BEGIN {require "/path/XML/Parser.pm"; import XML::Parser}
However that will still use @INC for anything that XML::Parser uses, and it looks like the package has various things that come with XML::Parser.
no subject
Date: 2008-01-02 12:19 pm (UTC)Since posting, I've got round it by writing my own XML parser for just the bits I needed (!), but I shall bear your @INC suggestions in mind for the future, thanks!