[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Letters to Numbers [Was - Re: [MacPerl] Hi there]



I was thinking -

$_ = "This turns letters into numbers";

$_ =~ s/\G(\s*)(\S+\s*)/{
   foreach $chr ((split('',$2))) {
      print (ord(uc($chr)) - 64);
   } }/ge;
print;


I know this works, but maybe this is simpler ...
$_ = 'abcdef';
foreach $chr (split('',$_)) {
    print (ord(uc($chr)) - 64);
}


There are many characters that this will not work on
Like these ... but you only mentioned Letters...


(Maybe this would be better discussed on FWP list?
 I'll post follow-ups there :)

HTH,  -Sneex-  :]
- FCCJ * 501 W State St * Jacksonville, Fl 32202 * 904/632-3089 -

> Could anyone help me out here, I need to replace letters [a-zA-Z] with
> numbers, as in a=1, b=2 etc. and I have no idea how to accomplish this
> without writing if clauses for every letter of the alphabet...uhm, does
> anyone know of a better, faster way to do this...perhaps a onelines?  =)
> 
> Also, I'm trying to split a long text into pairs of letters, and I have
> absolutely NO idea how to do this...I'm trying to make strings like
> "John is fat" turn into scalar values in an array that are "Jo", "hn",
> "is", "fa" "t and so on.  I need pairs of digits, that's it...and as
> much as I've pondered, I'm unable to find a solution.  And...one more
> thing, can you match odd and even numbers in Perl?


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe