Perl程序使用错误的参数

时间:2013-08-13 13:27:02

标签: linux perl command-line-interface

我正在尝试在perl中创建简单的启动脚本,它将在系统启动时启动各种程序。如下

my @startupPrograms = qw(google-chrome thunderbird skype pidgin );
my @pagesToBeOpenedInChrome = qw(http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox);

sub runPrograms() {
    print("Starting startup Programs... \n");
    foreach (@startupPrograms) {
        my $command = $_;
        print "Starting Program " . $command . "\n";
        if($command == "google-chrome") {
            foreach (@pagesToBeOpenedInChrome) {
                $command = $command . " " . $_;
            } 
        }
        `$command &`;
        print "Program " . $command . " started \n";
    }


}

但我得到的输出是

[aniket@localhost TestCodes]$ ./startUp.pl 
***** Welcome to startup program! *****
Starting startup Programs... 
Starting Program google-chrome
Program google-chrome http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started 
Starting Program thunderbird
Program thunderbird http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started 
Starting Program skype
Program skype http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started 
Starting Program pidgin
Program pidgin http://www.google.com/ http://stackoverflow.com/ https://mail.google.com/mail/u/0/#inbox started 

为什么要在每个命令中执行pagesToBeOpenedInChrome数组内容?此外,如果我把pidgin放在其他程序之前,它需要永远启动pidgin(其他程序被锁定)。任何帮助或建议表示赞赏。

1 个答案:

答案 0 :(得分:8)

变化

if($command == "google-chrome") {

if($command eq "google-chrome") {

在perl中,你使用eq或ne进行文本比较,使用==进行数值比较!

使用== for text基本上说如果$ command不为空或0

相关问题