【问题标题】:Error: perl Script is running twice错误:perl 脚本运行了两次
【发布时间】:2014-03-27 14:27:01
【问题描述】:

我编写了一个小脚本,从中调用另一个脚本。 代码: package.PL

use strict;
no warnings 'experimental::smartmatch';
use feature qw(switch);
print"\nPlease enter Perl Installation Path\n";
my $path=<>;
$path=~ s/^\s+|\s+$//;

while(1){
            print "\nEnter your Choice : \n";
            print "1.Premigration Script for active records\n";
            print "2.Premigration Script for archival records\n";
            print "3.Post Migration Script\n";
            print "4.Cleanup Script\n";
            print "5.Exit\n";
            my $input=<>;
            given($input){
              when(1) {system("$path/perl export_from_ddts.pl configfile_active.ini");system("$path/perl convert_to_csv.pl configfile_active.ini");}
              when(2) {system("$path/perl export_from_ddts.pl configfile_archived.ini");system("$path/perl convert_to_csv.pl configfile_archived.ini");}
              when(3) {system("$path/perl post_migration.pl configfile_active.ini");}
              when(4) { system("$path/perl cleanup.pl");}
              default {
                          if($input > 4){
                            print "\nYou want to exit the menu? y/n\n";
                            my $state=<>;
                            $state =~ s/^\s+|\s+$//g ;
                          if($state eq 'y'){
                            last;
                            }
                          else{
                            continue;
                        }
                    } 
                }
            }
}

如果我从 Package.pl 调用任何脚本,它会运行两次。 例如:如果我选择选项 1 为活动项目运行预迁移脚本,我会得到两次相同的输出。

perl 版本:5.18.1 我在 linux 中运行另一个 perl 安装(不是系统 perl)。

【问题讨论】:

    标签: perl perl-module


    【解决方案1】:

    一开始你可以使用$^X 作为Perl 的PATH 或者$EXECUTABLE_NAME 当你使用use English

    您看到两次输出? - 你的代码没问题。不使用任何 smartmatch 运算符时,为什么还要使用 no warnings 'experimental::smartmatch

    我已尝试重构您的代码,但它对我有用。

    【讨论】:

    • given/when 使用智能匹配运算符。
    猜你喜欢
    • 2015-11-07
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 2013-02-04
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多