Syl*_*son 2 windows perl executable space path
我在Windows上: - /在我的脚本中我有:
$ENV{'Powmig Path'}powermt
Run Code Online (Sandbox Code Playgroud)
那给了我:
C:\Program\ Files\EMC\PowerPath\powermt
Run Code Online (Sandbox Code Playgroud)
如果我做了if(-e $ENV{'Powmig Path'}powermt)它不起作用.
我尝试用一些替换来改变我的路径\ /
我也尝试添加更多双引号,但似乎没有任何工作:-(
例:
#!/usr/bin/perl
use strict;
use warnings;
use File::Spec;
if($^O =~ m/^MSWin32$/){
my $tmp = File::Spec->catdir($ENV{'Powmig Path'}, "powermt");
if(-e "\"$tmp\""){
print "powermt found\n";
}else{
print "No multipathing found \"$tmp\"\n";
}
$tmp =~ s/\\/\//g;
if(-e "\"$tmp\""){
print "powermt found\n";
}else{
print "No multipathing found \"$tmp\"\n";
}
}else{
print "Error: Unknow OS\n";
}
exit;
Run Code Online (Sandbox Code Playgroud)
输出:
C:\Users\sgargasson\Desktop>perl test.pl
No multipathing found "C:\Program Files\EMC\PowerPath\powermt"
No multipathing found "C:/Program Files/EMC/PowerPath/powermt"
Run Code Online (Sandbox Code Playgroud)
经过一些尝试不同的文件,从空间来的问题......
有人能帮助我吗?
高手中的Thx
您确实意识到您不能只在源代码中键入字符串,对吧?你需要引用它:
print "$ENV{'Powmig Path'}powermt";
...
if (-e "$ENV{'Powmig Path'}powermt")
Run Code Online (Sandbox Code Playgroud)
这将插入变量,在这种情况下是散列中的散列值%ENV,并将其与字符串连接powermt.
如果您尝试将字符串连接到变量,则首先需要引用它,然后使用运算符将其附加到变量:
my $string = $ENV{'Powmig Path'} . "powermt";
# ^--- concatenation operator
Run Code Online (Sandbox Code Playgroud)
但是,如果您尝试构建路径,则可以使用适合该任务的模块,例如File::Spec:
use strict;
use warnings;
use File::Spec;
my $path = File::Spec->catdir($ENV{'Powmig Path'}, "powermt");
Run Code Online (Sandbox Code Playgroud)