D
Dackle
I'm having a recurring problem reading in .csv files. The first line
in the file is always missing, and so when the code below executes,
$dt[0] will contain the second line, $dt[1] the third, and so on.
Usually I get around this by manually opening the .csv file in notepad
and inserting "DUMMY" and a carriage return, then resaving. Then when
the code executes, DUMMY is skipped, and $dt[0] containes the first
line, $dt[1] the second etc., which is how I want it. In general, this
manual process works fine, but I'd rather skip it if possible. Has
anyone encountered this problem before or knows why it is happening?
open SCORES, "C:/$filename.csv" or die "can't open file: $!";
while (<SCORES>) {
chomp;
@x=<SCORES>;
}
$n=@x+0; # Number of games
for $a (0..$n) {
@c=split(",",@x[$a]);
$dt[$a]=$c[0]; # Date
$vis[$a]=$c[3]; # Visitor
$hom[$a]=$c[6]; # Home
}
in the file is always missing, and so when the code below executes,
$dt[0] will contain the second line, $dt[1] the third, and so on.
Usually I get around this by manually opening the .csv file in notepad
and inserting "DUMMY" and a carriage return, then resaving. Then when
the code executes, DUMMY is skipped, and $dt[0] containes the first
line, $dt[1] the second etc., which is how I want it. In general, this
manual process works fine, but I'd rather skip it if possible. Has
anyone encountered this problem before or knows why it is happening?
open SCORES, "C:/$filename.csv" or die "can't open file: $!";
while (<SCORES>) {
chomp;
@x=<SCORES>;
}
$n=@x+0; # Number of games
for $a (0..$n) {
@c=split(",",@x[$a]);
$dt[$a]=$c[0]; # Date
$vis[$a]=$c[3]; # Visitor
$hom[$a]=$c[6]; # Home
}