多分少し読みやすいです:
# The BEGIN block is explained in perldoc perlmod
BEGIN {
# Prefix all dirs already in the include path, with root's perl path if it exists, or the
# current user's perl path if not and make perl look for modules in those paths first:
# Example:
# "/usr/lib/perl" => "/home/root/perl/usr/lib/perl, /usr/lib/perl"
my $root_user_perl_dir = '/home/root/perl';
# Fetch user home dir in a non-intuitive way:
# my $user_perl_dir = ( getpwuid($>) )[7] . '/perl/');
# Fetch user home dir slightly more intuitive:
my $current_userid = $>; # EFFECTIVE_USER_ID see perldoc perlvar
# See perldoc perlfunc / perldoc -f getpwuid
my ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell,$expire)
= getpwuid($current_userid);
my $current_user_home_dir = $dir;
my $user_perl_dir = $current_user_home_dir . '/perl/';
my $base_module_dir = '';
if (-d $root_user_perl_dir ) {
# Use this if the path exists
$base_module_dir = $root_user_perl_dir;
}
else {
# or fallback to current user's path
$base_module_dir = $user_perl_dir;
}
# Generate the new paths
my @prefixed_INC = map { $base_module_dir . $_ } @INC;
# Add the generated paths in front of the existing ones.
@INC = (@prefixed_INC, @INC);
}