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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.