Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: C code translation to Perl

by InfiniteSilence (Curate)
on Jan 31, 2012 at 03:27 UTC ( #950868=note: print w/ replies, xml ) Need Help??


in reply to C code translation to Perl

I'm with jethro, if you feel the need to use Pastebin and what-not to get help you appear to be having problems isolating the place where your code is having trouble. In other words, you are more likely to get help if you are more specific with the description of your error.

Before doing anything however, why can't the C code compile on Solaris (I don't have a Solaris VM or machine handy to answer the question for myself)? My thoughts are that if you could get it to compile then you could write an XS module from Perl to just use the functions you need. From a performance standpoint I cannot imagine how this would not be your best choice. Heck, even if the C code breaks it may be better to fix it and then follow the XS route rather than do this in Pure Perl.

Celebrate Intellectual Diversity


Comment on Re: C code translation to Perl
Re^2: C code translation to Perl
by bottch (Initiate) on Jan 31, 2012 at 08:51 UTC

    I printed every single variable already. First of all the crypt($pw,"Ho") statement returns different results. After I noticed that, I just set $pw to the value the c tool returns. Now $seed differs from the c code. It's wierd because the first 4-5 elements in the array are the same like in the c tool.

    Hexadecimal elements from @seed in Perl:
    seed: 2298 seed: effe9 seed: 329fb28 seed: f9f4815b seed: 7430a82151 seed: 277c8923528c seed: 11957511bac25e seed: 6a9a15bb7c3a5a5 seed: 53cb25459bf9ffe7 seed: 59b3b95dcd77f57d seed: a56ffe811a5b3cae seed: 4ffb834f11b60ab seed: 52dea09c13b9ef89

    Hexadecimal elements from seed in C:

    c: seed: 2298 c: seed: effe9 c: seed: 329fb28 c: seed: f9f4815b c: seed: 30a82151 c: seed: 8923528c c: seed: 11bac25e c: seed: b7c3a5a5 c: seed: 9bf9ffe7 c: seed: cd77f57d c: seed: 1a5b3cae c: seed: f11b60ab c: seed: 13b9ef89

    I have no clue why the values differs from the 5th element on. Thats why I'm asking here. Sorry for my incomprehensible question befor.

    regards bottch

      I have no clue why the values differs from the 5th element on.

      You are using a 64-bit perl, (or possibly a 32-bit Perl with 64-bit IVs enabled), which means that your attempts to reproduce the results from the C code which uses 32-bit integers isn't working.

      The type of bit-wise math in the C code relies heavily on the implicit mod 2**32 of intermediate results to work.

      For a way to 'fix' it, see Re: emulate 32-bit on perl 64.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Thanks a lot BrowserUK! You just kinda hit the bullseye :) Now everything works fine. Thanks again. regards,bottch

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950868]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-09-21 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls