feldmani
asked on
embedding Perl into C
I have an already written C program that also I have access to, is very spaghetti so we try not to work with it. I need to make modifications to the output, so I wrote a Perl program to do it, but I think I will need to run the perl code from inside C.
I found a way to do it in a book I have, but I don't know how to get the library directory needed since when I type
perl -MConfig -e "print $Config{archlib}
or
perl -Mconfig -e "print $Config{cc}
I get an error saying can't located $Config in @INC.
Any ideas on what to do for me?
I found a way to do it in a book I have, but I don't know how to get the library directory needed since when I type
perl -MConfig -e "print $Config{archlib}
or
perl -Mconfig -e "print $Config{cc}
I get an error saying can't located $Config in @INC.
Any ideas on what to do for me?
Does it say $ in the error message?
Rather than try to embed perl into your C program, why not pipe the output of the C program to the Perl program at the command level? This is typically how output post-processing is done.
myCprogram | perl -MConfig -e "print $Config{archlib}"
myCprogram | perl -MConfig -e "print $Config{archlib}"
ASKER
well, here is the problem. The C program creates two different files, a .wrk and a .txt.
The file that the perl modifies is the .wrk since the .txt would be MUCH harder to modify. I don't even know if unix would allow this to happen since it might still be locked for writing/reading. Hopefully it's open for at least reading which then I could get it to work.
The file that the perl modifies is the .wrk since the .txt would be MUCH harder to modify. I don't even know if unix would allow this to happen since it might still be locked for writing/reading. Hopefully it's open for at least reading which then I could get it to work.
Unix would probably allow it to be modified, however, if the C program has kept it open, the C program would overwrite the modified version when it does a close on the file.
Can you send .wrk to STDOUT so that the above pipe can work?
In what context did you type the comands which got an error?
You should probably be using ' instead of " so that the shell does not interpret the $Config,
but the error message you report is not the one I would have expected.
Can you send .wrk to STDOUT so that the above pipe can work?
In what context did you type the comands which got an error?
You should probably be using ' instead of " so that the shell does not interpret the $Config,
but the error message you report is not the one I would have expected.
ASKER
No, the C program closes it, but I don't know if it instantly allocates the rights back to the program. I MIGHT be able to send the .wrk to STDOUT, although I doubt it. I will try it however.
I typed the commands above in the unix shell script...Not sure what you mean by context. I tried it with the ' marks, and it still didn't work.
The full error is more like this (I don't want to put down the real directory since I don't know what it is):
Can't locate config.pm in @INC (@INC contains: /foo/perl5/foo/foo/fake_va riables .).
BEGIN failed--compilation aborted
I typed the commands above in the unix shell script...Not sure what you mean by context. I tried it with the ' marks, and it still didn't work.
The full error is more like this (I don't want to put down the real directory since I don't know what it is):
Can't locate config.pm in @INC (@INC contains: /foo/perl5/foo/foo/fake_va
BEGIN failed--compilation aborted
it should be Config not config
But why do you need Config?
But why do you need Config?
ASKER
Cause when I was reading how to embedd the perl into C code, the O'reilly book said I need to get those.
I've never had to run anything inside C, so I don't know exactly how to do it. I found several things in books and such on the topic, and they all said I would need this data before I can make perl work in C.
I've never had to run anything inside C, so I don't know exactly how to do it. I found several things in books and such on the topic, and they all said I would need this data before I can make perl work in C.
Could you have the perl program run after the c program is finished (and done making changes to the .wrk file). Then have the perl program make the changes necessary?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, martin. I think that might work. I will try it.