Can I transfer a array from perl to c without writhing anything to hdd? I could generate an array in perl, save it in a file and read in c. But is it possible to perform this operation in memory only?
2 Answers
You can use the Perl API to talk between Perl code and C, and this can all happen in memory (no writing out intermediate forms to disc).
The details of the various calls for handling arrays are avaialble from perl.org.
Remember though that the contents of the Perl array are Perl scalar values (SVs) not just ints or pointers as in a C array, so you'll have to use the Perl API to decode the data down to something you can handle in your C program.
Comments
This doesn't sound like a question about Perl or C at all, but a question about how to transfer information from one program to another ("I'd prefer to have external binary.") This is called inter-process communication (IPC).
If the Perl program launches the C program, you could pass the data using the argument list.
If the C program launches the Perl program, you create a pipe and tie it to the child's STDOUT. The Perl program would print the data to STDOUT, and the C program would read it from the pipe.
If neither of the two programs launched the other, a socket is the obvious solution, though there are many other possibilities.
XS, take a look at perlxstut: perldoc.perl.org/perlxstut.html - alternatively you could transfer the data via a separate process likememcached- provided you were happy to extend your C code to add the necessary client and format processing (in Perl this is easier)Cinsideperl?