http://www.perlmonks.org?node_id=1096243


in reply to Re: Calculations before using lib;
in thread Calculations before using lib;

As perl needs to know the arguments for use lib before calling lib's import method, every expression used there is implicitly in a BEGIN block equivalent. So I often use a construct like this in my code:

#!/usr/bin/perl use strict; use warnings; use FindBin (); use lib do { (my $dir=$FindBin::Bin)=~s|/foo/|/bar/|; $dir };

This can also be used with taint mode to untaint the value of $FindBin::Bin:

#!/usr/bin/perl -T use strict; use warnings; use FindBin (); use lib do { $FindBin::Bin=~m|^(/.*)| or die "Can't find myself"; "$1/ +../lib" };

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)