top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Embed perl interpreter and call C function from perl?

0 votes
480 views

http://perldoc.perl.org/perlembed.html

Above link only shows calling from C to perl.

What I want to do is to create a function in C code and somehow export it to my embedded perl interpreter. Then I want to be able to call this C function from perl code.

Can someone point me to a good example on how to do this?

posted Aug 19, 2014 by Kiran

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Calling a C program from Perl can be done with the XS mechanism. XS stands for eXternal Subroutine, and is the most common way to provide Perl-to-C linkage. However, you may need to learn something about Perl internals.

There is a tutorial about XS at the same website (or via the perldoc command-line program):

answer Aug 19, 2014 by Seema Siddique
Similar Questions
+1 vote

I'm looking for a hash function and a related function or operator such that:

 H(string1 . string2) = f(H(string1), H(string2))
 H(string1 . string2) = H(string1) op H(string2)

 where:
 H() is the hash function    
 string1 is a string
 string2 is a string    
 . is the string concatenation operator 
 f() is a function
 op is a binary operator

Any suggestions?

+1 vote
$ perl -le 'system "df -h"'
$ perl -le 'system "df","-h"'

Both two styles work fine. What's the difference between them and which is better usage?

0 votes

Do you know if there is a working module that can be used to post to WordPress from a Perl script? I've seen that all the modules that contain WordPress are very old.

I need to install that module under a Perl built with Perlbrew. I tried to install WordPress, WordPress::API, but they both depend on WordPress::XMLRPC which depends on SOAP::Lite which depends on XML::Parser which can't be installed because of the error "expat.h - no such file or directory".
I also tried to install XML::Parser::Expat but it gives the same error.

By curiosity I searched for a Python module, and I found python-wordpress-xmlrpc, I installed it very fast and easy, I found that it offers more features than the Perl module WordPress, I tested a sample script I found on the web, and it worked very well.

...