in reply to Re: Re: Help with parsing through a comma delimted file
in thread Help with parsing through a comma delimted file
The reason is that you will make fewer fencepost errors that way. (One of the most common bugs in C, but generally automatically avoidable in Perl.foreach my $i (0..$#line) { $record[$row]{$fieldname[$i]}=$line[$i]; }
Beyond that I would recommend using a -1 for the third argument to split, and given that you have tabular data I would lose the loop entirely for a slice:
(I would actually clean it up even more, more on that in another post.)my %rec; @rec{@fields} = split(/,/, $_, -1); $record[$row] = \%rec;
|
|---|