2013-03-25 56 views
2

我试图运行多个Perl的在PowerShell中的命令行命令在Windows 8在Windows 8 PowerShell ISE中运行草莓的Perl

这工作

perl -e "print 'Joe'"; 

此打印:

Joe 

这不起作用

perl -e "my $string = 'Joe'; print $string;" 

这给了我一个错误

perl : syntax error at -e line 1, near "my =" 
At line:1 char:1 
+ perl -e "my $string = 'Joe'; print $string;" 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo   : NotSpecified: (syntax error at -e line 1, near "my =":String) [], RemoteException 
+ FullyQualifiedErrorId : NativeCommandError 
Execution of -e aborted due to compilation errors. 

有人能指出明显的错误,我很想念?谢谢。我通常在UNIX上执行此操作,但使用返回刻度。作为包装而不是双引号。

+0

我不知道PowerShell,但它看起来变量'$ string'插入到'-e'代码*之前*它作为参数传递给Perl→更改分隔符。 – amon 2013-03-25 21:10:30

回答

8

试试这个,但我不能测试它

perl -e 'my $string = ''Joe''; print $string;' 

在PowerShell中$string是一个变量,而在双引号变量与赋值扩大。用单引号表示文字。 为了逃避'在单引号加倍它作为''

或尝试:

perl -e "my `$string = 'Joe'; print `$string;" 

的`在PowerShell中的转义字符。

+0

两者都有效。谢谢:) – 2013-03-25 21:16:27

+0

@ wall-nut很高兴为了帮助! – 2013-03-25 21:16:52