我有一些数据如下
S_ METHOD m0 : 47|8@0- (1,0) [0|0] ""
S_ CTRL m1 : 15|8@0- (0.01,-200) [0|0] ""
从2行以上我试图提取曲线括号()我写了一个perl脚本
my @temp_signal = split(":",$line);
my @signal= split(" ",@temp_signal[0]);
my @Factor_temp1 = split (" ",@temp_signal[1]);
my @factor_temp = split ('\(',@Factor_temp1[1]);
my @factor = chop(@factor_temp);
my @offset = split (",",@factor_temp);
print OUTFILE1 "@offset[0]\n";
print OUTFILE1 "$signal[1]\n";
但是当我试图打印@offset [1]& @offset [0]它打印一些其他值甚至不存在于行中如何获取值
1 0
0.01 -200
答案 0 :(得分:4)
您可以使用正则表达式匹配来提取用逗号分隔的括号内的内容:
if ( my @numbers = $line =~ /\((.*),(.*)\)/) {
print "$numbers[0] $numbers[1]\n";
}