Seriously, it took me about 5 minutes to understand your lengthy code, so I really wonder - what have you done so far to find out where your code does go wrong? Have you traced it in the debugger? Have you sprinkled diagnostic print or warn statements?
As a hint, Perl does not consider two strings identical if they differ in case. For example the following prints not equal:
my $col_name = 'P_DLRUOM'; my $entered_value = 'p_dlruom'; sub check_colname { if ($col_name eq $entered_value) { return 'equal'; }; return 'not equal'; };
If this hint is not yet enough information for you, compare the next code with the code you have in validate_fields:
sub validate_fields { my ($colvalue,$colname) = @_; if ($colname eq 'P_DLRUOM') { warn "Checking '$colvalue' for validity in 'P_DLRUOM':"; return validate_p_dlruom( $updateval ); } elsif ($colname eq 'FOO') { warn "Checking '$colvalue' for validity in 'FOO':"; return validate_foo( $updateval ); } else { warn "Unknown column name '$colname' passed."; return; }; };
Coincidentially, your whole data setup is horrible - you should store the whole information about your table in a data structure and then use that data structure to run your program instead of hardcoding all the column names and possible values. Perl has a very good data structure for such things, the hash. It maps names to other things, for example subroutines:
# Map the column name to the validator code: my %validator = ( P_12MONTHDEMANDQTY => \&validate_number, ... P_DLRUOM => \&validate_p_dlruom, ... ); sub validate_fields { my ($updateval, $colname) = @_; if (! exists $validator{ $colname }) { warn "'$colname' is not a valid column name."; }; my $code = $validator{ $colname }; if (! $code->($updateval, $colname)) { warn "'$updateval' is not a valid value for '$colname'."; } else { warn "'$updateval' is a valid value for '$colname'."; return 1 }; }
Far fewer opportunities to forget a value or to return the wrong value with this. You might want to do a search on dispatch tables here to learn more.
In reply to Re: Need help with Validation script
by Corion
in thread Need help with Validation script
by ssmith001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |