我有一个看起来像这样的文件:
[options42BuySide]
logged-check-times=06:01:00
logged-check-address=192.168.3.4
logged-check-reply=192.168.2.5
logged-check-vac-days=sat,sun
start-time=06:01:00
stop-time=19:00:00
falldown=logwrite after 10000
failtolog=logwrite after 10000
listento=all
global-search-text=Target Down. This message is stored;
[stock42BuySide]
logged-check-times=06:01:00
logged-check-address=192.168.2.13
logged-check-reply=192.168.2.54
logged-check-vac-days=sat,sun
start-time=06:01:00
stop-time=18:00:00
该脚本将列表细化为名称、开始和停止时间。
sellSide40, start-time=07:05:00, stop-time=17:59:00
SellSide42, start-time=07:06:00, stop-time=17:29:00
SellSide44, start-time=07:31:00, stop-time=16:55:00
42SellSide, start-time=09:01:00, stop-time=16:59:00
问题是我想用命令行参数从文件中过滤掉特定的名称。我正在尝试使用@ARGV 数组并将命令行值从@nametimes 数组中提取出来。就像是 :
capser@capser$ ./get_start_stop SorosSellSide42 ETFBuySide42
该脚本可以很好地解析文件 - 我只需要命令行数组的帮助
#!/usr/bin/perl
use strict ;
use warnings ;
my ($name , $start, $stop, $specific);
my @nametimes;
my $inifile = "/var/log/Alert.ini";
open ( my $FILE, '<', "$inifile") or die ("could not open the file -- $!");
while(<$FILE>) {
chomp ;
if (/\[(\w+)\]/) {
$name = $1;
} elsif (/(start-time=\d+:\d+:\d+)/) {
$start = $1;
} elsif (/(stop-time=\d+:\d+:\d+)/) {
$stop = $1;
push (@nametimes, "$name, $start, $stop");
}
}
for ($a = 0; $a >= $#ARGV ; $a++) {
$specific = (grep /$ARGV[$a]/, @nametimes) ;
print "$specific\n";
}
这可能很容易——但是我已经为此工作了好几天,而且我是这家商店中唯一使用 perl 的人。我没有人要问,谷歌搜索也没有成功。我提前道歉激怒了那些肯定会因为提出如此简单的问题而对我大喊大叫的perl神。