Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > migrating c code to perl

Reply
Thread Tools

migrating c code to perl

 
 
chetan
Guest
Posts: n/a
 
      01-13-2004
Is there any way (tool) to migrate/convert c code to perl ?

 
Reply With Quote
 
 
 
 
Martien Verbruggen
Guest
Posts: n/a
 
      01-13-2004
On Tue, 13 Jan 2004 08:49:54 +0530,
chetan <(E-Mail Removed)> 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?
|
 
Reply With Quote
 
 
 
 
chetan
Guest
Posts: n/a
 
      01-13-2004
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 <(E-Mail Removed)> 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


 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      01-13-2004
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$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com Python 56 12-27-2012 01:25 PM
Migrating C Code from OS2 to Windows skulkrinbait@googlemail.com C Programming 9 07-19-2006 09:56 PM
Migrating C Code from OS2 to Windows skulkrinbait@googlemail.com C++ 2 07-19-2006 03:23 PM
migrating Document.Write to Code Behind Jeronimo Bertran ASP .Net 4 11-14-2003 12:56 PM
UserDict -> dict, reasons for migrating existing code Andreas Kuntzagk Python 1 07-22-2003 01:10 AM



Advertisments