in reply to Re: A little golfing challenge: Replacing letters with numbers (edit)
in thread A little golfing challenge: Replacing letters with numbers
Hello, Veltro,
Nice idea with 'ord'!
I've tried your code, and it outputs:
Nice idea with 'ord'!
I've tried your code, and it outputs:
Here the newline is absent, and one extra trailing space, these are not problems I think. But some extra characters at the ending does solution wrong. (upd.:) Here I would suggest to modify printing line to one which converts undefined array elements to zero-length string, e.g.:3 4 4 4 4 19 18 22 6 13 10 19 2 8 6 18 20 16 1 10 6 19 3 2 19 20 3 18 +18 1 0
Which outputs (with extra space and without newline):print( $ar[ord $_] =~ s/.\K$/ /r );
upd. ...or back to '//' op (to avoid uninitialized value warnings):3 4 4 4 4 19 18 22 6 13 10 19 2 8 6 18 20 16 1 10 6 19 3 2 19 20 3 18 +18 1
print( ( $ar[ord $_] // '' ) =~ s/.\K$/ /r );
In Section
Seekers of Perl Wisdom