这个Perl代码有什么作用?
发布时间:2020-12-16 06:11:06 所属栏目:大数据 来源:网络整理
导读:在cPanel中,它们告诉您将此代码插入Perl文件的开头.我不确定它是做什么的.我已经在文件的开头尝试了有和没有这个的代码,似乎所有工作都是一样的.我没有用cron运行代码来测试它,但只有我自己.通过“测试它”,我的意思是使用打印线,数据库连接和返回,潜艇,变量
|
在cPanel中,它们告诉您将此代码插入Perl文件的开头.我不确定它是做什么的.我已经在文件的开头尝试了有和没有这个的代码,似乎所有工作都是一样的.我没有用cron运行代码来测试它,但只有我自己.通过“测试它”,我的意思是使用打印线,数据库连接和返回,潜艇,变量等……
BEGIN
{
my $base_module_dir = (-d '/home/root/perl' ? '/home/root/perl' : ( getpwuid($>) )[7] . '/perl/');
unshift @INC,map { $base_module_dir . $_ } @INC;
}
解决方法
也许更容易阅读:
# 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);
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
