Thread: Perl in C

  1. #1
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121

    Perl in C

    Is there a way to call perl from C and have the data be shared? In that I mean suppose I call a perl script from C and a variable in the perl script $a = 3, would there be a way during runtime to say that int a = $a.

    I know it wont be exactly like that but I hope you can see what I am getting at here. Shared memory between perl and c.

    Thank you!
    -- Will you show me how to c++?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's usually easier to start with perl and call C to do the bitty stuff.

    That's how a large number of perl modules get implemented.

    It should be easy enough to find plenty of perl resources to allow you to do that.

    There's also Simplified Wrapper and Interface Generator
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I've never done it, but you can embed perl in a C program (and as Salem says*, vice versa). Have a look here:

    perlembed - how to embed perl in your C program

    Actually looks fairly easy.

    *however I don't think you need to resort to SWIG to do it, there are some native perl features for this too.
    Last edited by MK27; 03-21-2010 at 02:35 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    I found this stuff in my perl book (O'Reilly Programming Perl). What I would like is to use perl as a scripting language sort of like lua is. I am more curious about the shared memory. I suppose that the examples provided allow me to retrieve a value which is fine as well and will work for what I want I think. Next beast comes to getting it to work in windows.

    Thank you guys!
    -- Will you show me how to c++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ v's Perl
    By kmcghee in forum C++ Programming
    Replies: 8
    Last Post: 08-13-2005, 10:37 AM
  2. C structure in perl typemap
    By rotis23 in forum Linux Programming
    Replies: 1
    Last Post: 07-16-2003, 11:13 AM
  3. perl program question
    By newbie2c in forum Tech Board
    Replies: 2
    Last Post: 02-03-2003, 10:19 AM
  4. From Perl to C
    By Heavenstrash in forum C Programming
    Replies: 4
    Last Post: 06-19-2002, 01:22 AM
  5. perl need help pls.....
    By magnum38 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-12-2001, 10:35 PM