Hello Perl Monks,
I have a csv file where I store things like, some table names, functions to execute etc. Sample:
Table1, getTableID('DBO','Table2')
I am writing a perl program that will read this file. Then when it sees a subroutine (which I can either use a regex or just append it as SUB:getTableID('DBO','Table2'), wherein I will read second portion of string delimited by : to get value as getTableID('DBO','Table2')), from my perl program, I need to execute it as a subroutine and give a return value.
If I simply print the content of file, I will get getTableID('DBO','Table2')
If suppose getTableID('DBO','Table2') returns value 100, I want the perl progrm to print 100 instead of the string: getTableID('DBO','Table2')
view my.csv
Table1, getTableID('DBO','Table2')
view demo.pl
sub getTableID($$) {return 100;} open FH, "my.csv" or die $!; while(<FH>) { chomp; push(@arr, $_); }close FH; foreach my $line(@arr) { my @arr1 = split(",",$line); my $val1 = $arr1[0]; my $func = $arr2[1]; print $func; ## This prints getTableID('DBO','Table2') ## I want it to actually execute the sub and print return ## value 100 }
In reply to How to read flat file and execute a subroutine inside that flat file in my main program by udday.shank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |