Some random notes on some useful Perl modules

Some random notes on Perl
FindBin
mkdir and File::Path


FindBin
If there are two modules using FindBin from different directories under the same interpreter, this won’t work. Since FindBin uses a BEGIN block, it’ll be executed only once, and only the first caller will get it right. This is a problem under mod_perl and other persistent Perl environments, where you shouldn’t use this module. Which also means that you should avoid using FindBin in modules that you plan to put on CPAN. To make sure that FindBin will work is to call the again function:

use FindBin;
FindBin::again(); # or FindBin->again;
In former versions of FindBin there was no again function. The workaround was to force the BEGIN block to be executed again:

delete $INC{‘FindBin.pm’};
require FindBin;

mkdir and File::Path
To recursively create a directory structure, look at the make_path function of the File::Path module.

Leave a Reply

Your email address will not be published. Required fields are marked *

14 − 10 =