MLUG: Re: [MLUG] simple perl one-liner question
Re: [MLUG] simple perl one-liner question
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Thu, 12 Apr 2007, Mike Miller wrote:

I'm looking back at the old messages because I'm interested in finding a simple way to convert letters A-Z to numbers 1-26. That has to be really easy!


This seems to do it:

perl -pe 's/([A-Z])/ord($1)-64/eg'

I would also like to add a space before the number (that used to be a letter), but if I insert a space, like so...

perl -pe 's/([A-Z])/ ord($1)-64/eg'

...it is ignored.  I could do this but I'm sure it is unnecessarily long:

perl -pe 's/([A-Z])/ $1/g ; s/([A-Z])/ord($1)-64/eg'

That works but it is not pretty.

Mike

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members