in reply to Need a Help - calling C program from Perl

I tried this. I was curious.
I downloaded the module from cpan.
cpan> install Inline::C
during install it asked me for my compiler.
i told it 'cc'. It completed install.
Got a sample from here, CPAN Inline::C
and added a Content-type header. I noticed that 'use strict;' did
not work with this module on my RHL6.2.8.
Besides that, the following test script
worked great in the shell and a browser.
#!/usr/bin/perl -w ##use strict; use Inline C; greet('Content-type:text/html'); greet('Hello from c via CGI'); __END__ __C__ void greet(SV* sv_name) { printf("%s\n\n", SvPV(sv_name, PL_na)); }

Here's the output from my error logs when strict was on.
Bareword "C" not allowed while "strict subs" in use at c.pl line 3. BEGIN not safe after errors--compilation aborted at c.pl line 3.
The CPAN link above has a lot of information about useage.
I tried your original .so example but no dice.
But the CPAN link talks about linking your .so,
read more cause i don't know squat.
Was fun to try though. BTW i did this in perl5.005

Replies are listed 'Best First'.
Re: Re: Need a Help - calling C program from Perl
by BrowserUk (Patriarch) on Oct 24, 2002 at 13:38 UTC

    use Inline C;

    should be

    use Inline::C;?

    That would allow you to use strict.


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
Re: Re: Need a Help - calling C program from Perl
by true (Pilgrim) on Oct 24, 2002 at 19:53 UTC
    If you read the documentation or try to run a test script. Use 'Inline C' is the only way to include this. You cannot call this with 'Inline::C' but 'Inline C'. Check the Inline C Documentation.
    Here's a quote from the cpan author.
    You never actually use Inline::C directly. It is just a support module + for using Inline.pm with C. So the usage is always: use Inline C => +...;
    If you know of a way to get around this i would love to hear it.

    edited:tone :)

      Think of "use" as a function call, with specialized first argument, which is a bareword representing a name, then followed by arbitrary parameters:

      use Module ( $arg1, $arg2, ... );

      So now, think of this:

      use Inline C;

      The first argument ("Inline") is special, so that's ok, but what about the second argument, "C"? It's a bareword. That should raise the flag at which point you say, "Oh, I need to quote it!"

      use Inline 'C';

      Ah, but why did it work when it was

      use Inline C => ...;

      you say? The answer is simple. It's the same reason why the first example below works, but not the second one:

      use strict; foo( FOOBAR => 'baz' ); foo( FOOBAR, 'baz' );

      Yep, the "key" is automatically stringified upon encountering "=>". So when you look at the Inline example, you can clearly see that that's using this stringification trick.

      Just for the record, from perlop:

      The => digraph is mostly just a synonym for the comma operator. It's useful for documenting arguments that come in pairs. As of release 5.001, it also forces any word to the left of it to be interpreted as a string.

      P.S. - you really should reply to the post that you refer to in your node, otherwise the poster to whom you're replying to may not notice