in reply to Invoke sub whose name is value of scalar
[ You asked me to comment on your update. It was a while ago, so I hope this is still useful to you. ]
This sounds like the perfect situation for a dispatch table.
# Setup my %validators = ( is_int => \&is_int, is_string => \&is_string, is_yyyy_mm_dd_date => \&is_yyyy_mm_dd_date, ); # Load configuration my @validators; while (<$config_fh>) { # Or whatever my ($col, $validator_name) = /^col(\d+)=(\w+)$/ # or die; exists( $validators{$validator_name} ) or die; $validators[$col] = $validators{$validator_name}; } # Process data. my $csv = Text::CSV->new(sep_char => ';'); while (<$data_fh>) { $csv->parse($_) or die; my @fields = $csv->fields(); for my $i ( 0..$#validators ) { my $validator = $validators[$i]; next if !defined( $validator ); $validator->($fields[$i]) or die; } }
|
|---|