migrating c code to perl

Discussion in 'Perl Misc' started by chetan, Jan 13, 2004.

  1. chetan

    chetan Guest

    Is there any way (tool) to migrate/convert c code to perl ?
     
    chetan, Jan 13, 2004
    #1
    1. Advertising

  2. On Tue, 13 Jan 2004 08:49:54 +0530,
    chetan <> wrote:
    > Is there any way (tool) to migrate/convert c code to perl ?


    None that I know of. If there was such a tool, I probably wouldn't use
    it, and I certainly wouldn't trust it.

    There are many things that work in C, are very idiomatic, but which
    are just not the right way to approach things in Perl. There are
    things that are possible in C, and simply not possible at all in Perl.

    For example, walking a string in C by incrementing a pointer until you
    reach a null byte, is normal in C. In Perl, that is not what you do.

    Another example is the use of machine-specific register tricks, or
    machine-specific address tricks. In (machine-specific variants of) C
    you can set a pointer to a fixed address, which is meaningful to the
    machine, and then manipulate or read that address. You can't do that
    in Perl.

    Trying to translate C into Perl on a code line by line basis will
    always end up with bad code, and most often with something ugly,
    unmaintainable, if it is possible at all.


    If you can't rewite the logic in Perl, maybe you should try to make
    your C code available as a library, and provide some access points to
    this library to Perl, with XS, SWIG, Inline::C or soemthing like that.

    The question is: Why do you want to rewrite it? The best option
    depends on the answer you give to that question.

    Martien
    --
    |
    Martien Verbruggen |
    Trading Post Australia | What's another word for Thesaurus?
    |
     
    Martien Verbruggen, Jan 13, 2004
    #2
    1. Advertising

  3. chetan

    chetan Guest

    i have a tool written in c. Need to have the same functianlities in perl
    so that they could be a part of an existing framework which is already
    there in perl. I am going through "perlxs and friends" (i am fresh to
    the world of perl). was thinking if there are similar utilities which
    could help me atain my goal.
    I agree with you that most of the aspects couldnt be taken care of
    when we want to convert c to perl and you are right, line by line
    conversion doesnt make any sense..i agree with you in this...
    will check out SWIG Inline and similar stuff.
    Thanks for the suggestions :)


    Martien Verbruggen wrote:
    > On Tue, 13 Jan 2004 08:49:54 +0530,
    > chetan <> wrote:
    >
    >>Is there any way (tool) to migrate/convert c code to perl ?

    >
    >
    > None that I know of. If there was such a tool, I probably wouldn't use
    > it, and I certainly wouldn't trust it.
    >
    > There are many things that work in C, are very idiomatic, but which
    > are just not the right way to approach things in Perl. There are
    > things that are possible in C, and simply not possible at all in Perl.
    >
    > For example, walking a string in C by incrementing a pointer until you
    > reach a null byte, is normal in C. In Perl, that is not what you do.
    >
    > Another example is the use of machine-specific register tricks, or
    > machine-specific address tricks. In (machine-specific variants of) C
    > you can set a pointer to a fixed address, which is meaningful to the
    > machine, and then manipulate or read that address. You can't do that
    > in Perl.
    >
    > Trying to translate C into Perl on a code line by line basis will
    > always end up with bad code, and most often with something ugly,
    > unmaintainable, if it is possible at all.
    >
    >
    > If you can't rewite the logic in Perl, maybe you should try to make
    > your C code available as a library, and provide some access points to
    > this library to Perl, with XS, SWIG, Inline::C or soemthing like that.
    >
    > The question is: Why do you want to rewrite it? The best option
    > depends on the answer you give to that question.
    >
    > Martien
     
    chetan, Jan 13, 2004
    #3
  4. Also sprach chetan:

    > Is there any way (tool) to migrate/convert c code to perl ?


    No, but you can make an XS module that uses the C code base. I did that
    once for File::Locate which was the only Perl module so far that merely
    took me one afternoon to complete. I simply copied the relevant code
    from the GNU findutils and added the necessary stuff from the perlapi.

    Perl and C work together exceptionally well, therefore integrating C
    into Perl is often a better solution than rewriting (it wont result in a
    penalty-hit eithe).

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
     
    Tassilo v. Parseval, Jan 13, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeronimo Bertran

    migrating Document.Write to Code Behind

    Jeronimo Bertran, Nov 13, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    2,746
    Kevin Spencer
    Nov 14, 2003
  2. Andreas Kuntzagk
    Replies:
    1
    Views:
    351
    Steven Taschuk
    Jul 22, 2003
  3. Replies:
    9
    Views:
    277
    Keith Thompson
    Jul 19, 2006
  4. Replies:
    2
    Views:
    313
    Richard Herring
    Jul 19, 2006
  5. Replies:
    56
    Views:
    747
    alex23
    Dec 27, 2012
Loading...

Share This Page