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

[FWP] 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 Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe