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

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



OK; how about:

$_ = "Changes Letters 2 Numbers.";

# This solution ignores everything that isn't a Letter...

# First, lowercase:
$_ =~ tr/A-Z/a-z/;

#         We can't use this:  $_ =~ tr/a-z/0-9/;
# Because we would get this:
#          0123456789 9999999999 999999
#          abcdefghij klmnopqrst uvwxyz

# So, we must be more literal:
$_ =~ tr/a-j,k-t,u-z/0-9,0-9,0-5/;

print;

__END__

What the above does:
0123456789 0123456789 012345
abcdefghij klmnopqrst uvwxyz

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

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


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org