Perl <-> C language interaction

A

Amontec, Larry

Hi all,

I have to parse ASCII text file and then to use the the parsed data to a
C program. Than the C program will act on an dedicated external USB
device via its dedicated driver.

Perl is just great to do the parse of the text file, since the text file
is not so structured.

My question: how can I interact between a perl script to a C program. I
mean I will have pointer of structure to pass to the C program.

Are there any tutorial or other paper describing the mechanisms and
possibilities we have to do.

Best regards,
Laurent

------------ And now a word from our sponsor ---------------------
For a secure high performance FTP using SSL/TLS encryption
upgrade to SurgeFTP
---- See http://netwinsite.com/sponsor/sponsor_surgeftp.htm ----
 
J

John Bokma

Amontec said:
Hi all,

I have to parse ASCII text file and then to use the the parsed data to a
C program. Than the C program will act on an dedicated external USB
device via its dedicated driver.

Perl is just great to do the parse of the text file, since the text file
is not so structured.

Why not use tools for C? (flex/bison). If you really want a parser, there
is not much difference between C and Perl (ie. you specify a grammer, make
/generate a lexer and a parser, and process the parse tree).

Often using regexps only work in very simple cases. It might be that this
is the case, and again: there are regexp libs for C (even Perl compatible
ones).
My question: how can I interact between a perl script to a C program. I
mean I will have pointer of structure to pass to the C program.

Are there any tutorial or other paper describing the mechanisms and
possibilities we have to do.

There are several ways to interact, you can embed perl in C (perldoc
perlembed), write a module in C with a Perl API, use sockets, shared
memory, XML RPC, etc, etc.

For simple parsing most, if not all, sound like a lot of overhead to me.
 
T

Thomas Kratz

Hi all,

I have to parse ASCII text file and then to use the the parsed data to a
C program. Than the C program will act on an dedicated external USB
device via its dedicated driver.

Perl is just great to do the parse of the text file, since the text file
is not so structured.

My question: how can I interact between a perl script to a C program. I
mean I will have pointer of structure to pass to the C program.

In addition to the pointers already given, have a look at the Inline
module and Inline::C.

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 
D

Daniel Zinn

Larry said:
My question: how can I interact between a perl script to a C program. I
mean I will have pointer of structure to pass to the C program.

You want to have a look at swig .... http://www.swig.org/

Best regards,
Daniel

PS: But you also can do it with a lexer/parser, etc in C/C++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top