Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: A little golfing challenge: Replacing letters with numbers

by rsFalse (Chaplain)
on Feb 21, 2019 at 21:13 UTC ( [id://1230330]=note: print w/replies, xml ) Need Help??


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:
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
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.:
print( $ar[ord $_] =~ s/.\K$/ /r );
Which outputs (with extra space and without newline):
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
upd. ...or back to '//' op (to avoid uninitialized value warnings):
print( ( $ar[ord $_] // '' ) =~ s/.\K$/ /r );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-26 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found