in reply to string error message
Anyway, since you have some sort of error-trapping already in place, and you are getting errors that seem to indicate unexpected features in the input data, your next step should be to do some more elaborate checking for data that doesn't match the expected pattern.
It'll be easier if you create a list of field names, and use a hash with those field names as keys:
(I tried to make that match your long list of variables, but you'll want to double-check. It compiles, but is untested. Updated to remove an unwanted "$" from the "fld_types" array.)# assuming a row of data in $_, and row number == $. my @fld_names = qw( begin agency district ssn serv_per_m serv_per_y serv_per_t last_name first_name middle_name cover_group pay_code pay_rate earnings holder ret_pcnt surv_ben work_sch cont_amt cont_code stuf +f ); my @fld_types = qw( \d \d+ \d+ \d+ \d+ \d+ \d \D+ \D \D \d+ \d+ \d+ \d+\D \s+ \d+ \d+ \d+ \d+\D \d+ .* ); my @fld_vals = ( /(.)(....)(...)(.{9})(..)(..)(.) (.{10})(.)(.)(.{5})(..)(.{8}) (.{7})(.{8})(....)(...)(...)(.{6})(..)(.*)/x ); # now do some testing of values... for my $i ( 0 .. $#fld_names ) { if ( $fld_vals[$i] !~ /^ $fld_types[$i] $/x ) { warn sprintf( "Data row %d: bad value in field %d (%s): %s\n", $., $i, $fld_names[$i], $fld_vals[$i] ); } } my %fields; @fields{@fld_names} = @fld_vals;
BTW, you need to learn to put <c> ... </c> around code and data when you post -- you can update the OP to add these tags, so that the code is readable.
|
|---|