如何将shell脚本转换为Perl脚本?
我有一个10k行shell脚本,并希望将其转换为Perl.是否有任何工具正在这样做,或者有没有办法做到这一点?
我有这个导致问题的Perl子例程:
sub new
{
my $class = shift;
my $ldap_obj = Net::LDAP->new( 'test.company.com' ) or die "$@";
my $self = {
_ldap = $ldap_obj,
_dn ='dc=users,dc=ldap,dc=company,dc=com',
_dn_login = 'dc=login,dc=ldap,dc=company,dc=com',
_description ='company',
};
# Print all the values just for clarification.
bless $self, $class;
return $self;
}
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题:
我收到此错误无法修改Core.pm第12行,"$ ldap_obj"附近的标量赋值中的常量项
例如:
在Perl中:
@array = (1,2,3);
system ("/tmp/a.sh @array" );
Run Code Online (Sandbox Code Playgroud)
在我的shell脚本中,如何在shell脚本中处理这个数组?如何处理shell脚本以接收参数,以及如何在shell脚本中使用该数组变量?
如何检查UNIX时间是1天之前
例如:UNIX时间是1308715355
我想找到那个时间1天或者现在没有
use Moose;
extends 'TEST::Role';
has 'name' => (
is => 'ro',
isa => 'Str',
default => 'me',
);
Run Code Online (Sandbox Code Playgroud)
这适用于perl 5.8.5但不适用于5.8.8.
怎么解决?
String found where operator expected at B.PM line 4, near "extends 'TEST::Role'"
(Do you need to predeclare extends?)
Run Code Online (Sandbox Code Playgroud) bash脚本如何确保运行的副本不多于一个?
我试过了:
ps -ef| grep /user/loca/shell/sh | wc -l
Run Code Online (Sandbox Code Playgroud)
由于grep命令,这显示了我2 .将其更改为:
ps -ef | grep /user/loca/shell/sh | grep -v 'grep' wc -l
Run Code Online (Sandbox Code Playgroud)
然后它显示1.但是,如果我vim /user/loca/shell/sh然后执行:
ps -ef| grep /user/loca/shell/sh | grep -v 'grep' wc -l
Run Code Online (Sandbox Code Playgroud)
这表明2.但是我只有一个过程,我已经开始了.
bash脚本如何检查进程是否正在运行?
例如:从日期开始: 10/02/2010
如何10/02/2010 00:00:00在Perl中转换相等的时间戳
我不能使用当地时间或时间..有没有其他方法来实现这一点..
我试过这个:
$string ="Group: ALL:ALL:Good";
@str2 = split (/:/,':',2);
print "@str2";
Run Code Online (Sandbox Code Playgroud)
我正在寻找$str[0] = Group 和$str[1]= ALL:ALL:Good.
它不起作用.会有什么问题?