2010-08-11 123 views
2

在我的小perl腳本(test.pl)返回代碼1我做的,以便從程序退出,如果 EXIT_STATUS等於1perl的+從Perl腳本

if ($EXIT_STATUS == 1 ) 
     { 
      system (exit); 
     } 

以下,但我也需要得到從test.pl返回代碼1

例如

./test.pl

回聲$?

如何使EXIT_STATUS = 1返回代碼1?

lidia

回答

5

這不是你應該如何在perl中退出。它是:

if ($EXIT_STATUS == 1) { 
    exit 1; 
} 

,如果你想正常,否則退出:

if ($EXIT_STATUS == 1) { 
    exit 1; 
} 
else { 
    exit 0; 
} 

或(取決於你的意圖)更簡單地說:

exit $EXIT_STATUS; 

見:http://perldoc.perl.org/functions/exit.html