简体   繁体   English

从带有 2 个条目的 Windows 命令行执行 Perl 脚本

[英]Executing Perl script from windows-command line with 2 entry

this is my Perl script这是我的 Perl 脚本

use strict;
use warnings;
use XML::Twig;
use Data::Dumper;

sub xml2array{
my $path = shift; 
my $twig = XML::Twig->new->parsefile($path); 
return map { $_ -> att('VirtualPath') } $twig -> get_xpath('//Signals');
} 

sub compareMappingToArray {
my $mapping = shift;
my $signalsRef = shift; 
my $i = 1;

print "In file : $mapping\n";

open(my $fh, $mapping);
while (my $r = <$fh>) {
    chomp $r; 


    if ($r =~ /\'(ModelSpecific.*)\'/) {
        my $s = $1;


        my @matches = grep { /^$s$/ } @{$signalsRef};

        print "line $i : not found - $s\n" if scalar @matches ==0;
        print "line $i : multiple $s\n" if scalar @matches > 1;
    }

    $i = $i + 1 # keep line index
 }
}

my $mapping = "C:/Users/HOR1DY/Desktop/Global/TA_Mapping/CAN/CAN_ESP_002_mapping.pm";      
my @virtualpath = xml2array("SignalModel.xml");
compareMappingToArray($mapping,  \@virtualpath);

The script works well, the aim of it is to compare the file "SignalModel.xml" and "CAN_ESP_002_mapping.pm" and putting the lines that didn't matches in a .TXT file.该脚本运行良好,其目的是比较文件“SignalModel.xml”和“CAN_ESP_002_mapping.pm”,并将不匹配的行放入 .TXT 文件中。 Here is how the .TXT file looks like:下面是 .TXT 文件的样子:

In file : C:/Users/HOR1DY/Desktop/Global/TA_Mapping/CAN/CAN_ESP_002_mapping.pm
line 331 : not found - ModelSpecific.EID.NET.CAN_Engine.VCU.Transmit.VCU_202.R2B_VCU_202__byte_3
line 348 : not found - ModelSpecific.EID.NET.CAN_Engine.CMM_WX.Transmit.CMM_HYB_208.R2B_CMM_HYB_208__byte_2
line 368 : not found - ModelSpecific.EID.NET.CAN_Engine.VCU.Transmit.VCU_222.R2B_VCU_222__byte_0

But for this script, I put the two files that need to be compare inside of the code and instead of doing that, I would like to run the script in windows cmd line and having something like:但是对于这个脚本,我将需要比较的两个文件放在代码中,而不是这样做,我想在 windows cmd 行中运行脚本并具有类似的内容:

C:\Users>perl CANMappingChecker.pl -'file 1' 'file 2'

All the files are in .zip file so if I can execute the script that he goes inside and take the 2 files that I need for comparison, it should be perfect.所有文件都在 .zip 文件中,所以如果我可以执行他进入的脚本并获取我需要比较的 2 个文件,它应该是完美的。 I really don't know how to do and what to put inside my script to make that in the cmd windows.我真的不知道该怎么做以及在我的脚本中放入什么以在 cmd 窗口中制作它。 Thanks for your help !谢谢你的帮助 !

Program (or script) parameters are stored in the @ARGV array.程序(或脚本)参数存储在@ARGV 数组中。 shift and pop without any parameter will work on @ARGV when used outside of a sub, in a sub they operate on @_.当在 sub 之外使用时,没有任何参数的shiftpop将在 @ARGV 上工作,在 sub 中它们对 @_ 进行操作。

See Archive::Zip for zip file handling.有关 zip 文件处理,请参阅Archive::Zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM