Using "d*" worked perfectly. I was able to create a c double array and directly feed that to matlab to plot the points.
Now, my goal is to pass strings also so I can define plot options. I have an array of strings in perl that I want to convert to an array of char * in C. Is there a way to use pack() to do this? It looks like all the pack options for char and strings just concatenate everything together. Thanks...Brady -----Original Message----- From: Jonathan Segal [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:40 AM To: bbcannon Cc: [EMAIL PROTECTED]; Elizabeth Mattijsen Subject: RE: Instantiating arrays with Inline The whole idea of pack is that you convert number types into a byte stream, which perl represents as a string -- pack always creates a string. Using Inline, it is easy to get the string as a char * in C. When you get the "char *" in C, though, if you have packed in one of the "native" formats, you can interpret the contents of the string as native machine data -- i.e. as a C array. You are letting pack do the work of converting a perl array into a C array for you (remember an array in C is just a contiguous chunk of memory with the same type of data over and over in a row). so if you, pack with, say, "l!", you will get longs (for long you need the ! to ensure that you get native length): my $list = pack( 'l!*',(65,66,67,68,69) ); #printf "%vd\n",$list; cLinePlot($list,$list,5); __DATA__ __C__ void cLinePlot(char * x, char *y, int els) { long *long_x = (long *)x; long *long_y = (long *)y; /* ... */ } But if you use "i" you get ints: my $list = pack( 'i*',(65,66,67,68,69) ); #printf "%vd\n",$list; cLinePlot($list,$list,5); __DATA__ __C__ void cLinePlot(char * x, char *y, int els) { int *int_x = (int *)x; int *int_y = (int *)y; /* ... */ } etc. you can read a lot on pack from : http://www.perldoc.com/perl5.6.1/pod/func/pack.html (aka perldoc -f pack) Hope this helps. -JAS
