This should work (but beware - it is untested :)

Rob



    my @required = qw(head1 head6 head8);
    my $line;

    for (<DATA>)
    {
        chomp;
        my @field = split /,/;
        my %column;                 # hash relating column header to column
index

        next unless @field;         # Ignore blank lines

        # If we're on the first data line then remember the
        # array index for each column header
        #
        # After the first line process each field corresponding
        # to a required header
        #
        if ($line++ == 0)
        {
            my $i;
            $column{$_} = $i++ foreach @field;
        }
        else
        {
            foreach (@required)
            {
                my $field = $field[$column{$_}];
                process ($field)
            }
        }
    }

    sub process
    {
        :
    }



"News.Support.Veritas.Com" <[EMAIL PROTECTED]> wrote in
message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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 extract fileds that match
the
> respective header values I want. Can anyone guide me in the best direction
> to achieve either option.
>
> Thanks
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to