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
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
"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;
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 ..
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"
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
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