Wow - okay, I guess it all makes sense now. Input was from DOS file, and I hadn't set $/ ! So the unchomped \x0d was remaining with the final field and making havoc, esp. with printing. But if you're interested:

Here is snippet of code that builds the @colnames array, reads input, and stores input fields into %input_fields so that each field can be referenced by column name:


        [snip]

        my $k_DOS                          # DOS line ending
                = "\x0d\x0a";

>> DUH! Now need to 'local $/ = $k_DOS;'

        [snip]
        open( my $infh, "$tsv_files_path/$filename" )
            or die "Couldn't open $filename";

        ##########################################################
        # Read Line 1: Column Headers - read into array.
        ##########################################################

>>      my $line = <$infh>;                  # read line 1
>>      chomp $line;                         # remove line ending

>>      my @colnames = split( $k_field_delim, $line );

        # TBD !! crosscheck configuration against these column names to
# validate that the column name the configuration file refers to are
        # actually in the file.

        #############################################################
        # Lines 2 and up: read line into hash, keyed by col name
        #############################################################

        my %input_field;    # maps col names to field contents
        my $val;
        my $const_val;      # TBD !! figure out better way to handle

    TSV_LINE:
>>      while ( defined( $line = <$infh> ) ) {
>>          chomp $line;
            ####################################
            # Perform record-level tests
            ####################################

            # Check that actual number of tab-separated fields in
            # input record equals number of columns from header.

            $qa{$filestem}{'#RECORDLVL'}{'record_length'}{$schno}[0]++;
            if ( 1 + ( $line =~ tr/\t// ) != @colnames ) {
$qa{$filestem}{'#RECORDLVL'}{'record_length'}{$schno} [1] = 0; $qa{$filestem}{'#RECORDLVL'}{'record_length'}{$schno} [2]++; next TSV_LINE; # If record length messed up, don't continue
            }

>> @input_fie...@colnames} = ( split( $k_field_delim, $line ) );
     [snip]

Here are first two records of input file (rec 1 contains column names):

00000000 53 63 68 6f 6f 6c 49 44 09 53 74 75 64 65 6e 74 | SchoolID.Student| 00000010 5f 4e 75 6d 62 65 72 09 41 74 74 5f 44 61 74 65 | _Number.Att_Date| 00000020 09 41 74 74 65 6e 64 61 6e 63 65 5f 43 6f 64 65 |.Attendance_Code| 00000030 09 41 74 74 65 6e 64 61 6e 63 65 5f 43 6f 6d 6d |.Attendance_Comm| 00000040 65 6e 74 0d 0a 32 09 31 30 30 31 38 31 09 30 31 |ent.. 2.100181.01| 00000050 2f 31 36 2f 32 30 30 39 09 55 4e 56 09 55 6e 76 |/ 16/2009.UNV.Unv| 00000060 65 72 69 66 69 65 64 0d 0a 32 09 31 30 30 31 38 |erified.. 2.10018|

Thanks for looking, guys.
Chap

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to