Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Interfacing Perl with other languages

by salva (Canon)
on Feb 08, 2008 at 10:24 UTC ( [id://666948]=note: print w/replies, xml ) Need Help??


in reply to Interfacing Perl with other languages

You have to write an interface between the two languages, and for that there are two tipical ways:
  • Using a socket: both languages run in their own process space and some kind of RPC is used to call one into the other through the socket. You have to serialize the data crossing the interface and deserialize at the other side while remaping it to the other language types. Using something standard as XML or YAML for the serialization is an option, but it has a big overhead.
  • Using XS (or Inline, SWIG, etc.): both languages run in the same process and the data is converted between the two languages using some C code. You have to provide a set of functions on every side of the interface to call the other language (for instance, on the language calling perl: perl_call_sub, perl_call_method, perl_eval). That solution is usually much faster, but you have to program it in C/XS.

If you tell us what is your target language, we would be able to give more specific indications about how it can be done.

Replies are listed 'Best First'.
Re^2: Interfacing Perl with other languages
by MistaMuShu (Beadle) on May 16, 2008 at 18:23 UTC

    Thank you all for the fantastic replies. I thought Inline was a very interesting bit of Perl. I also appreciate the pointers towards perl4caml and CamelBones.

    The question came out so vague because I was simply curious about the issue of how various languages played nice with one another. Solutions that I already knew about include setting up XML-RPC, SOAP, or some other interface that's interoperable between languages. I know almost nothing about XS, but I think that's the solution I was more interested in.

    I originally thought of the question when I was going through some particularly nasty legacy perl code. I thought the code was perfect for a basic CRUD webapp in Rails. However, since there were many other legacy systems that depended on the legacy code, I wanted to make a Ruby interface to the legacy code, and use that Ruby interface in the webapp. Wrapping around the legacy code would allow me to design away all the years of hacks and be able to test it at the same time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://666948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-07-17 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.