Attempting to place the C code as a string directly into the benchmarking script, a new error was produced.

Error. You have specified 'C' as an Inline programming language. I currently only know about the following languages: Foo, foo If you have installed a support module for this language, try deleting + the config-xxx-xxx-xxx-5.020003 file from the following Inline DIREC +TORY, and run again: C:/Users/home/Desktop/.Inline (And if that works, please file a bug report.) at ./calcit.pl line 14. BEGIN failed--compilation aborted at ./calcit.pl line 14.

So it may be that there needs to be some further modules installed for Strawberry Perl to use Inline.pm with C.

Replacing END with DATA unfortunately still produces the original Error. I tried to open Inline::DATA as a file handle, but I couldn't quite apply IO calls to pseudo Handles. Also tried various permutations of the examples on C-PAN and in the Cookbook. See below for Code which produced new error. Also note Inline::Files did not install when I ran the cpan install Inline cmd

#!perl use strict; use warnings; use File::Spec::Functions qw/catfile/; use lib catfile('C:', 'Users', 'home', 'Perl5', 'lib', 'perl5' ) ; use Time::HiRes qw(gettimeofday tv_interval); #use Test::More; #use c_calc; #use perl_calc; use Inline C => '<<END_C'; double my_abs(double num) { return (num > 0)? num : -num; } double calc_pi() { double real_pi = 3.14159265358979; double my_pi = 0; double step_sign = 1; unsigned long long i = 1; while(my_abs(real_pi - my_pi) > 0.00000001) { my_pi += 4.0/i * step_sign; step_sign *= -1; i += 2; } return my_pi; } END_C my $start_time_c = [ gettimeofday ]; my $c_calc = calc_pi(); #c_calc::calc_pi(); my $end_time_c = [ gettimeofday ]; my $elapsed_c = tv_interval($start_time_c,$end_time_c); my $start_time_perl = [ gettimeofday ]; my $perl_calc = 3.14159 ** 2.71828; #perl_calc::calc_pi(); my $end_time_perl = [ gettimeofday ]; my $elapsed_perl = tv_interval $start_time_perl,$end_time_perl); my $differences = abs($elapsed_perl - $elapsed_c); #if(ok($c_calc == $perl_calc, "Pi number calc")) if($c_calc != $perl_calc) { print "C computation time = $elapsed_c\n"; print "Perl computation time = $elapsed_perl\n"; print "Differences = $differences\n"; } #done_testing;

Frustratingly, when no use of the DATA symbol occurs there are still attempts to read the unopened handle. Hope this helps progress the issue. DC.


In reply to Re: Using module with c code in perl program. by Don Coyote
in thread Using module with c code in perl program. by k0shinus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.