http://www.perlmonks.org?node_id=969029


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;