Thanks for all! It's working now, i just needed to replacing __END__ to __DATA__.

I need to write simple script, which calling functions from two modules (one of it contains perl code and another contains c code), measuares the time of each and if they calculation results are equals printing time differences of calulation. Problem is that when i include module with c code and run main script perl says: "readline() on unopened filehandle DATA at C:/other_perl/Strawberry/perl/site/lib/Inline.pm line 360. Use of uninitialized value $data in substitution (s///) at C:/other_perl/Strawberry/perl/site/lib/In line.pm line 360. Use of uninitialized value $data in split at C:/other_perl/Strawberry/perl/site/lib/Inline.pm line 3 61. No source code in DATA section for Inline 'C' section. at optest.pl line 0. INIT failed--call queue aborted. One or more DATA sections were not processed by Inline." Here is the main script:

use Time::HiRes qw(gettimeofday tv_interval); use Test::More; use perl_calc; use c_calc; $start_time_c = [ gettimeofday ]; $c_calc = c_calc::calc_pi(); $end_time_c = [ gettimeofday ]; $elapsed_c = tv_interval($start_time,$end_time); $start_time_perl = [ gettimeofday ]; $perl_calc = perl_calc::calc_pi(); $end_time_perl = [ gettimeofday ]; $elapsed_perl = tv_interval($start_time,$end_time); $differences = abs($elapsed_perl - $elapsed_c); if(ok($c_calc == $perl_calc, "Pi number calc")) { print "C computation time = $elapsed_c\n"; print "Perl computation time = $elapsed_perl\n"; print "Differences = $differences\n"; } done_testing;

Here is module with c code:

package c_calc; use Inline 'C'; 1; __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; }

I read Inline::C-Cookbook, but i didn't find an answer there. So what i do wrong?


In reply to 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.