我是Perl的新手。我正在使用Perl读取CSV文件。CSV的第一列是时间(浮点数)。我已经阅读了CSV并成功显示了CSV的内容。此外,我希望将CSV数据用于某些计算。我需要时间列作为数组(或任何数据结构)。在读取时间列并将其存储在数组中时,它会以字符串形式存储。我希望有一个用于算术运算的数字数组。
我尝试添加0,mul 1,然后使用sprintf将其存储在数组中,但遇到错误。
use v5.30.0;
use strict;
use warnings;
my $file = $ARGV[0] or die;
open(my $data, '<',$file) or die;
my @timeArray;
while(my $line = <$data>){
chomp $line;
my @words = split ",",$line;
#my $temp=$words[1]*1;
my $temp=sprintf "%.6f",$words[1];
push @timeArray,$temp;
}
错误:
Argument ""67.891947295"" isn't numeric in multiplication (*) at 3.pl line 12, <$data> line 19556.
and
Argument ""67.840034174"" isn't numeric in sprintf at 3.pl line 13, <$data> line 19555.
另外,为什么在“”“”中使用自变量。
重新“非常容易安装”,...并使用!