Re: Checking header is csv file for accuracy

2002-12-19 Thread Steve L
I will incorporate the for -> while change you suggest.With regard to parse methods, I was intending to use the parse_csv subroutine suggested in Perl Cookbook for parsing actual data. I have tested this out and it seems to work just fine (having previously been caught out splitting CSV files). I

Re: Checking header is csv file for accuracy

2002-12-19 Thread Jenda Krynicky
From: "Rob Dixon" <[EMAIL PROTECTED]> > "Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message > 3E01E02F.17624.1ED52A1C@localhost">news:3E01E02F.17624.1ED52A1C@localhost... > > From: "Perl" <[EMAIL PROTECTED]> > > > This should work (but beware - it is untested :) > > > > > > Rob > > > > > > my

Re: Checking header is csv file for accuracy

2002-12-19 Thread Rob Dixon
"Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message 3E01E02F.17624.1ED52A1C@localhost">news:3E01E02F.17624.1ED52A1C@localhost... > From: "Perl" <[EMAIL PROTECTED]> > > This should work (but beware - it is untested :) > > > > Rob > > > > my @required = qw(head1 head6 head8); > > my $line;

Re: Checking header is csv file for accuracy

2002-12-19 Thread Jenda Krynicky
From: "Perl" <[EMAIL PROTECTED]> > This should work (but beware - it is untested :) > > Rob > > my @required = qw(head1 head6 head8); > my $line; > > for () It's much better to use while () This "for ()" forces Perl to read the whole file into an array in memory. (Well ..

Re: Checking header is csv file for accuracy

2002-12-19 Thread Perl
Sorry - to check that the headers exist change the first part of the if() statement to: if ($line++ == 0) { my $i; $column{$_} = $i++ foreach @field; foreach (@required) { die "Column $_ doesn't exist"

Re: Checking header is csv file for accuracy

2002-12-19 Thread Perl
This should work (but beware - it is untested :) Rob my @required = qw(head1 head6 head8); my $line; for () { chomp; my @field = split /,/; my %column; # hash relating column header to column index next unless @field; # I

Checking header is csv file for accuracy

2002-12-19 Thread news.support.veritas.com
Before working with lines in a csv file I would like to check the headers from the file for accuracy i.e. do the headers I expect exist, and are they in the right order. Alternatively, and even better, I would like to check all headers I require exist, then for each parsed line extract only extrac