use strict;
use warnings;
my $file = 'tagged.txt';
open(my $info, '<', 'tagged.txt') or die $!;
while(my $line = <$info>){
if ($line =~ /someString/){
#
} else if ($line =~ /someOtherString/){
#
}
#...
}
close $info
所以我试图将一些狂野的日志文件解析成格式良好的.csv文件。我想逐行查看日志文件,并检查我所需的值/字符串之一是否出现在该行中。假设我们有类似的东西:
Aug 27 13:59:36 topas user.info POS[548]: 00:11:33.989304 <GPS> Input To Sensor Fusion - f64Longitude (deg) = 13286667
我感兴趣的其中一个值是例如f64Longitude(度),分别是后面的值“f64Longitude(deg)=”。 我现在的问题是:我如何访问之后的字符串我发现的一些regEx ...
答案 0 :(得分:2)
只需指定您要查找的令牌,并使用正则表达式组检索匹配的部分。例如:
my $str = 'Aug 27 13:59:36 topas user.info POS[548]: 00:11:33.989304 <GPS> Input To Sensor Fusion - f64Longitude (deg) = 13286667';
if ($str =~ /f64Longitude \(deg\) = (\d+)/) {
print $1;
}
#prints 13286667