Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I have a C program which reads temperatures from a circuit I have built. An example function is as follows -
float Get_Temperature();
If I wanted to use this function in a Perl program how would I go about it? Also, if I had the following C function -
BOOL isThisHot(int);
how would I go about using it in a Perl program, thanks for your help.
Alan

code tags by holli

Replies are listed 'Best First'.
Re: Integrating Perl and C
by davorg (Chancellor) on Jun 21, 2006 at 15:31 UTC

      perlxstut is probably a better starting point, but you'll make your way to the other eventually. But yeah, Inline::C might be the better option. There's also always SWIG, too (if you were interested in using other languages as well).

Re: Integrating Perl and C
by ikegami (Patriarch) on Jun 21, 2006 at 15:44 UTC

    If you are using a Windows machine and your function is in a DLL, you could also use Win32::API:

    use Win32::API (); my $Get_Temperature = Win32::API->new( 'mydll', 'float Get_Temperature()', ); my $isThisHot = Win32::API->new( 'mydll', 'BOOL isThisHot(int)', ); my $temp = $Get_Temperature->Call(); my $hot = $isThisHot->Call($temp);

    or

    use Win32::API (); Win32::API->Import('mydll', 'float Get_Temperature()'); Win32::API->Import('mydll', 'BOOL isThisHot(int)'); my $temp = Get_Temperature(); my $hot = isThisHot($temp);