Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: A little golfing challenge: Replacing letters with numbers (edit)

by Veltro (Hermit)
on Feb 21, 2019 at 19:37 UTC ( #1230323=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict ;
    use warnings ;
    ...
    foreach ( @F ) {
        print( ($ar[ord $_] // $_ ) . " " ) ; 
    }
    
  2. or download this
    perl '-M5;@ar[map { ord } split "","\0ARNDBCEQZGHILKMFPSTWYV"] = 0..12
    +7' -alpe '($_=$F[0])=~s/(.)/($ar[ord $1])." "/ge' input.txt
    # or
    perl '-M5;@ar[map { ord } split "","\0ARNDBCEQZGHILKMFPSTWYV"] = 0..12
    +7' -alpe '($_=$F[0])=~s/(.)/(defined $ar[ord $1] ? $ar[ord $1] : $1 )
    +." "/ge' input.txt
    
  3. or download this
    # 'defined' is optional:
    perl '-M5;@ar[map { ord } split "","\0ARNDBCEQZGHILKMFPSTWYV"] = 0..12
    +7' -alpe '$_=~s/(.)/(defined $ar[ord $1] ? $ar[ord $1]." " : $1 )/ge'
    + input.txt
    
  4. or download this
    perl '-M5;@ar[map { ord } split "","\0V\0B\0L\0\0\0Q\0\0\0\0\0\0\0E\0\
    +0\0\0\0\0\0\0\0\0P\0\0I\0\0\0\0\0\0Z\0H\0\0\0\0\0\0\0\0Y\0J\0\0S\0\0\
    +0\0\0D\0\0\0X\0\0\0\0\0K\0\0\0R\0\0\0\0W\0\0\0\0\0U\0\0\0\0A\0\0M\0\0
    +\0F\0\0\0C\0\0T\0\0\0\0O\0\0\0\0\0\0\0\0\0\0N\0G\0\0\0\0"] = 0..127' 
    +-alpe '$_=~s/(.)/($ar[ord $1] ? $ar[ord $1]." " : $1 )/ge' input.txt
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2020-11-30 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?