Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: A little golfing challenge: Replacing letters with numbers -- oneliner

by Discipulus (Canon)
on Feb 21, 2019 at 09:40 UTC ( [id://1230286]=note: print w/replies, xml ) Need Help??


in reply to A little golfing challenge: Replacing letters with numbers

Hello haukex

similar?

perl -M"0;@h{split'','ARNDBCEQZGHILKMFPSTWYV'}=(1..22)"-pne "s/([A-Z]) +/$h{$1} /g"

L*

update (also edited the title for personal indexing purpose)

perl -pe 's/[A-Z]/(index" ARNDBCEQZGHILKMFPSTWYV",$&).$"/ge' input.txt

shorter..

perl -pe 's/\S/(index" ARNDBCEQZGHILKMFPSTWYV",$&).$"/ge' input.txt

the above is wrong.. but..

perl -pe 's/\w/(index"0ARNDBCEQZGHILKMFPSTWYV",$&).$"/ge' input.txt




> The trick with golfing is to wait for Discipulus to have a good idea and steal it from him :P.

best perl compliment I received!

PS

meh.. I had a -1 for not coresponding string in index also it seems that second column is not wanted..

..so a longer version is needed

perl -pe 's/\s.//,s/\w/(index"0ARNDBCEQZGHILKMFPSTWYV",$&).$"/eg' input.txt

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found