Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-28 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found