in reply to Efficient way to do field validation

You could build a hash of regexes, something like this (the regexes are just given as quick simplistic examples, I haven't thought very carefully about them).

my %validate = ( INT => qr /^[+-]?\d+$/, DEC => qr /^[+-]?\d*\.?\d*$/, #etc. );

and then use it to validate your individual fields.

You might actually take it one step further and build a dispatch table, something like this:

my %actions = ( INT => sub { return 1 if $_[0] =~ /^[+-]?\d+$/}, DEC => sub { return 1 if $_[0] =~ /^[+-]?\d*\.?\d*$/}, VARCHAR(5)=> \&validate_varchar_5(@_), #etc. );

This is a very rough untested example, I just want to convey the general idea.

You don't say enough about what you have done to figure out whether these techniques will be beneficial.

Replies are listed 'Best First'.
Re^2: Efficient way to do field validation
by govindkailas (Acolyte) on Aug 01, 2013 at 05:20 UTC
    Thanks a lot, I was thinking about something similar like this. This made things clear to me.