http://qs1969.pair.com?node_id=517395


in reply to Doubts of a perl beginner on PERLEMBED

(3) My third question is ---I have to call 2 different perl subroutines in 2 different perl files from a C file. So i want to know whether i will to have initialize 2 seperate occurances of "PerlInterpreter" . If it is possible to use same "PerlInterpreter" for calling 2 different perl files ,could you please specify how.
Is there any reason you can't just combine the two files into one?

You can probably load both files into the same perl interpreter using require. So something like

char *my_args = { "perl", "-e", "require 'file1.pl'; require 'file +2.pl'" }; ... perl_parse(my_perl, NULL, 3, my_args, (char **)NULL);
might well work for you. (Of course it will cause problems if both files use the same subroutine name.)

Replies are listed 'Best First'.
Re^2: Doubts of a perl beginner on PERLEMBED
by jithoosin (Scribe) on Dec 17, 2005 at 09:48 UTC
    Hi Robin,

    Thanks for the good & useful replies. I will not be able to combine 2 perl files into one . And one of my aims is to invoke the perl interpreter only once. In your example i have seen "perl" as the first argument for "my_args". What does that signify? .Usually people put that field as empty ("") .And one more thing is that whether specifying "perl" as the first argument of "my_argv" may cause the perl intepreter to be invoked every time i call a perl subroutine.
      You're being rather mysterious, which makes it harder to give helpful answers. (Why can't you combine the two scripts into one? Why do you aim to invoke the Perl interpreter only once?)

      I don't think the first element of argv is used. I prefer to set it to ‘perl’ because, logically, it’s supposed to be the name that the program was invoked with. But set it to ‘fiddlesticks’ if you prefer – I don’t think it will make any difference to the result.

        Hi

        The reason for not combining 2 different files is that they are for different functionality.One for extracting html tags from a html file anc checking whether which all browser version supports them and other file is for checking the html error in they file using "TIDY". And i donot believe in combining 2 different files which provides entirely different functionalities to complicate matters.

        Actually previously these 2 files have been called by "system" command in C and "popen" was used for passing and getting arguments between C and perl.But this reduced speed of execution. So i am trying to increase the speed by embedding perl in C

        Any way THANKS for all your replies and suggestion & helping novices like me.Always keep this good mind with you.
Re^2: Doubts of a perl beginner on PERLEMBED
by jithoosin (Scribe) on Dec 19, 2005 at 06:10 UTC
    Hi ,
    Sorry for disturbing you again. As I had to call subroutine named "test" in file 'file1.pl i used
    char *my_argv[] = {"","-e","require 'file1.pl';require 'file2.pl';" }
    and then used
    call_argv("test",G_DISCARD,args);
    But i am getting error Undefined subroutine &main::test called.What could be the reason

    UPDATE : The error was not shown when i included "perl_run" after perl_parse.What could be the possible reason?
      The files file1.pl and file2.pl are loaded by the require statements. If you don't execute the require statements (by running the script) then the files won't be loaded. Simply compiling the one-liner isn't enough to load the files.