我在这个上使用了Spreadsheet :: XLSX插件,并且我试图根据用户提供的独特的位置代码'来尝试从电子表格中获取IP信息。 (指定为$ xxcode)。
我的目标是找到'位置代码的行号。在电子表格中给出然后收集数据,我遇到的问题是只有在“地点代码”的情况下才会出现问题。提供的是直到循环实际中断的第一个结果。其他方面,它一直运行,直到XLSX结束并出错。
use strict;
use warnings;
use Spreadsheet::XLSX;
my $iplog = Spreadsheet::XLSX -> new ('C:\path\workbook.xlsx',);
my %iplogcol = ( "ip" => 2, "subnet" => 3, "gw" => 4, "locdes" => 1 );
my $codecol = 0;
my $row = 1;
my $xxcode = <STDIN>;
my $worksheet = $iplog -> Worksheet('Sheet1');
my $xxcell = $worksheet->get_cell($row,$codecol);
my $xxvalue = $xxcell->value();
until ($xxcode==$xxvalue) {
my $xxcell = $worksheet->get_cell($row,$codecol);
my $xxvalue = $xxcell->value();
printf ("Current Code: $xxvalue\n Looking for: $xxcode\n");
$row=$row+1;
};
for my $loop (keys %iplogcol) {
my $cell = $worksheet->get_cell($row,$iplogcol{$loop});
my $value = $cell->value();
printf ("$loop value is: %s\n", $value);
}
当我使用第二个值运行脚本时输出:
C:\Users\Josh\scripts\perl\prechecklist>precheck2.pl
Please enter the site number you would like to configure:2124
Current Code: 2125
Looking for: 2124
Current Code: 2124
Looking for: 2124
Current Code: 2123
Looking for: 2124
Can't call method "value" on an undefined value at C:\Users\Josh\scripts\perl\pr
echecklist\precheck2.pl line 23, <STDIN> line 1.
最后一个错误&#39;无法调用方法&#34;值&#34; ..等等&#39;是因为第3行后电子表格是空白的
这是我使用第一个值运行脚本的时候:
C:\Users\Josh\scripts\perl\prechecklist>precheck2.pl
Please enter the site number you would like to configure:2125
locdes value is: 100 East ABC St.
ip value is: 1.1.1.1
gw value is: 1.1.1.2
subnet value is: 255.255.255.252
任何帮助将不胜感激!
干杯,
约书亚
答案 0 :(得分:2)
您正在$xxvalue
循环中重新声明until
。新值不用于比较,因此您将永远循环。例如:
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my $foo = 42;
my $bar = 17;
until ($foo == $bar) {
say "Before 'my': $bar";
my $bar = 42;
say "After 'my': $bar";
}
会反复输出
Before 'my': 17
After 'my': 42
Before 'my': 17
After 'my': 42