Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Javascript to Perl = fail

by Not_a_Number (Parson)
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;


Comment on Re: Javascript to Perl = fail
Select or Download Code
Re^2: Javascript to Perl = fail
by sweepy838 (Acolyte) on May 05, 2012 at 19:25 UTC
    hi, this would be the encoded text http://pastebin.com/mHaZ3NBf

      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:

      fqAv@nbj@Aqsetfdxx@Am%@gh80676

      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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-12-18 04:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls