Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Javascript to Perl = fail

by Not_a_Number (Prior)
on May 05, 2012 at 09:22 UTC ( #969029=note: print w/replies, xml ) Need Help??

in reply to Javascript to Perl = fail

I couldn't follow the logic of your JS code, so I ran it as is on my machine. Here's the output:

D:\progs\javascript>j test.js fodpefe!ufyu0

It seems that the aim is to increase the numeric (ascii+) value of each character in the string by 1, then add a zero on the end. Testing with a number of other random strings appears to confirm this analysis.

So here's how I'd translate the code into Perl:

my $str = 'encoded text'; say join '', ( map { chr ord( $_ ) + 1 } split //, $str ), 0;

Update: Further testing reveals that your code also, for some reason, strips all digits except zero from the string. Easy peasy:

say join '', ( map { chr ord( $_ ) + 1 } grep /[^1-9]/, split //, $str ), 0;

Replies are listed 'Best First'.
Re^2: Javascript to Perl = fail
by sweepy838 (Acolyte) on May 05, 2012 at 19:25 UTC
    hi, this would be the encoded text

      Please explain why you pointed me to that site.

      Is it some encoded text that your JS script is supposed to decode? If so, you should have entitled your OP Javascript = fail, since all I get when I run the text through your code is garbage:


      Or am I missing something? Maybe my confusion has something to do with the fact that the OP was anonymous, but the latest question was posed by sweepy838?

      Please elucidate.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969029]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-06-18 02:19 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.