You can't. The semantics of Perl and C are sufficiently different that there is no simple way to automatically convert one into the other -- and certainly there is none that would output readable and idiomatic code.

The best way forward depends on the outcome you want. It might be appropriate to wrap parts of the C code in XS or to incorporate them with Inline::C, as others have suggested above; or (given that XS can be somewhat baroque) it might be simpler to have a separate C program that your Perl program interfaces with through some IPC mechanism.

But if what you actually need is to end up with a pure-Perl program that does exactly the same thing as the existing C program, without itself using any C code at all, then the only satisfactory way to get that is to have someone who is experienced with both C and Perl sit down, read the C, understand the algorithms it's using, and reimplement those in Perl from scratch.


In reply to Re: C to perl by Porculus
in thread C to perl by jonam

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.