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

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.