[英]Loops in array with split using Perl
Using split
with values in an array. 对数组中的值使用
split
。
($field[1],
$field[2],
$field[3],
$field[4],
$field[5]) = split(",", $line);
I read in a file. 我读了一个文件。
Using split
, take each value after the delimiter ,
using an array. 使用
split
,取各值的分隔符之后,
使用阵列。
There are five files on each line, so as you can imagine, I want to take in one line per loop iteration. 每行有五个文件,因此,您可以想象,我希望每个循环迭代占用一行。
Any advice on how to do this? 有关如何执行此操作的任何建议?
You could do this: 您可以这样做:
while (<$fh>){
my @tmp;
@tmp = split(/,/,$line);
warn "Less than 5 items on a line: $line\n" if scalar(@tmp) != 5;
}
or you could use Text::CSV to read the file 或者您可以使用Text :: CSV读取文件
while ($line = < F >)
{
@clpData= split(/,/, $line);
print "@clpData[9]\n";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.