2017-04-07 53 views
0

我有以下代碼:Perl的傳遞參數在Windows

$op = shift or die "Usage: rename expr [files]\n"; 
chomp(@ARGV = <STDIN>) unless @ARGV; 
print "$op"; 

for (@ARGV) 
{ 
    print "$_"; 
    $was = $_; 
    eval $op; 
    die [email protected] if [email protected]; 
    rename ($was, $_) unless $was eq $_; 
} 

它產生的Linux機器上,即在預期的結果,當我運行

perl massrenamer.pl 's/\.txt/\.txtla/' *.txt 

我得到正確的結果。我嘗試執行Windows機器上同樣的事情,並安裝像

perl massrenamer.pl 's/\.txt/\.txtla/' *.txt 

perl massrenamer.pl "s/\.txt/\.txtla/" *.txt 

perl massrenamer.pl 's/\.txt/\.txtla/' "*.txt" 

草莓perl的,但我沒有得到任何結果。有人可以幫忙嗎?

回答

2

Wilcard擴展外殼環境進行的,而不是當參數被封閉引號之間,對窗口端口Perl腳本有一個模塊的Win32 :: AutoGlob see also this SO question

速戰速決:更換(@ARGV) (glob「@ARGV」)

$op = shift or die "Usage: rename expr [files]\n"; 
chomp(@ARGV = <STDIN>) unless @ARGV; 
print "$op"; 

for (glob "@ARGV") 
{ 
    print "$_"; 
    $was = $_; 
    eval $op; 
    die [email protected] if [email protected]; 
    rename ($was, $_) unless $was eq $_; 
}