in reply to How to convert a script from C to Perl?

You have a number of problems with this code:

1) You need to get the source for util.c as presumably fmakeword(), plustospace(), unescape_url() are in there.

2) Past that, the code just will not work. For example, the subroutine num2Pstring() returns a pointer to a dynamically allocated stack variable - that just will not fly - barf, die, croak. So the assumption that you have "good" C code is wrong.

3) You might be better off generating a program spec of what you want this thing to do and having somebody write a new version of it for you.

  • Comment on Re: How to convert a script from C to Perl?

Replies are listed 'Best First'.
Re^2: How to convert a script from C to Perl?
by lyklev (Pilgrim) on Oct 26, 2010 at 20:29 UTC

    I agree with Marshall, you need to have the code for num2Pstring fixed, this is very broken. Besides, it seems to be a bad reinvention of the sprintf function.

    The source of util.c is on the same web server (simply tried it, seems to work).

    After that, compiling the program is by far the easiest option and that is not very difficult if you know how.

    Converting this program to Perl is not going to change anything: the c-program works as a CGI program (I can see that from the code), for which the web server has to be configured by the sysadmin. If you have your program converted to Perl, you would still have to run it as a CGI program (there are different options, but those are waaay more difficult).

Re^2: How to convert a script from C to Perl?
by Anonymous Monk on Oct 26, 2010 at 19:12 UTC
    Thanks for taking the time to look at the program so carefully! That's very helpful.

    Some version of the code appears to be working at Colby (because they have a working website using it) but, based on what you've said, it appears that the real code is different from what they posted on that page.

    I'll make one more attempt to get the correct code from Colby and then I'll give up and hire a programmer like you suggest.

    (original poster)

      The program is quite simple and easy to translate, for someone that know C and Perl. As an exercise, I wrote a translation. It is very quick and dirty and I wouldn't run it on a public server without further review, but it might get you going. It's a bit too big to post here, but you can download it from my scratchpad. I'll leave it there for a few days.

      but, based on what you've said, it appears that the real code is different from what they posted on that page.

      It is possible for the code to run correctly even with that nasty bug.

      It definitely does not hinder a translation to Perl. The direct translation «sub { my $x; ... return $x; }» isn't buggy.