my $input_file; my $line; open( $input_file, '<', $ARGV[0] ) or die "Open file $ARGV[0] failed $!"; while ($line = <$input_file>) { chomp $line; my @fields = split(/\|/, $line); #Check if record is a valid record type if ($fields[0] !~ /$record_types/) { fatal_error (2, "record contains invalid file type fields[0] - Record: $line"); exit 0; } #Check if number of fields in record matches the number in the record layout my $expected_nbr_of_fields_in_record = keys %{$rec_layout_hash{$fields[0]}}; my $actual_fields_count = @fields; if ($actual_fields_count != $expected_nbr_of_fields_in_record) { fatal_error (1, "record does not contain correct number of fields - Expected $expected_nbr_of_fields_in_record but record contained $actual_fields_count fields - $line"); exit 0; } #Process each field from the input data one field at a time for (my $i = 1; $i <= $actual_fields_count; $i++) { my $j = $i; $j -= 1; #$j is minus 1 because the fields array starts at zero, whilst the actual field number in the record array starts at 1 #Determine which sub routine is required to check the data from the record_layout hash my $sub_routine = $rec_layout_hash{$fields[0]}{$i}{"sub_routine"}; #Call sub routine and pass the actual field day and the expected length of the fiel my $value1 = $fields[$j]; my $value2 = $rec_layout_hash{$fields[0]}{$i}{"field_length"}; &{ $sub_routine } ($value1, $value2); } }