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 | |
by Not_a_Number (Prior) on May 06, 2012 at 12:59 UTC |