我有一个文本文件temp.txt,其中包含条目,
cinterim=3534
cstart=517
cstop=622
ointerim=47
ostart=19
ostop=20
Run Code Online (Sandbox Code Playgroud)
注意:键值对可以按新行排列,也可以一行排列在一行中.
我正在尝试使用Perl在DB中打印和存储这些值以获得相应的键.但是我收到很多错误和警告.现在我只是想打印这些值.
use strict;
use warnings;
open(FILE,"/root/temp.txt") or die "Unable to open file:$!\n";
while (my $line = <FILE>) {
# optional whitespace, KEY, optional whitespace, required ':',
# optional whitespace, VALUE, required whitespace, required '.'
$line =~ m/^\s*(\S+)\s*:\s*(.*)\s+\./;
my @pairs = split(/\s+/,$line);
my %hash = map { split(/=/, $_, 2) } @pairs;
printf "%s,%s,%s\n", $hash{cinterim}, $hash{cstart}, $hash{cstop};
}
close(FILE);
Run Code Online (Sandbox Code Playgroud)
有人可以提供帮助来完善我的计划.