开发者

how to embed perl script in c program? [closed]

开发者 https://www.devze.com 2023-03-16 20:58 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answe开发者_如何学编程red in its current for
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answe开发者_如何学编程red in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Actually I've got an idea but to do that I need your help.Tell me is there any way to create a library in perl script ? I mean what is the command to create a library in perl ?and how can i include that library in my c program and run it ? I read somewhere that you can embedd your perl script in your c program but how can I make it?I want to create a special library on strings using perl script and use it in my c program.Help me guys.Thank you.


To actually include a perl interpreter in your C program and be able to execute perl code, see http://perldoc.perl.org/perlembed.html. Since perl is an interpreted language, there isn't a mandatory step of creating a library from your perl code.

But again, you really need to do some basic reading to learn at least the rudiments of the language first.


Of course, Perl allows you to reuse code by creating modules:

Foo.pm

package Foo;

use strict;
use warnings;

sub bar {
    print "foobar";
}

1;

Later, you could reuse the code in a script like:

foobar.pl

#!/usr/bin/env perl

use strict;
use warnings;

use Foo;

Foo::bar;

Quoting yourself (cody):

Guys perl is not as easy i thought its so confusing thing.

To learn Perl, try following a book like Learning Perl, or tutorials on the internet like Perl Beginners' Site or Learn Perl.


In most cases, the best way to do it is by a system call:

#include <stdlib.h>

int main ()
{
  int RetVal, Arg1, Arg2;
  RetVal=system ("perl Script.pl Arg1 Arg2");
  return 0;
}

If you also need to analyze the script's output, you can redirect it to a file and read the file in C.

0

精彩评论

暂无评论...
验证码 换一张
取 消