Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: map and grep or clear code?

by johngg (Canon)
on Jan 31, 2012 at 11:36 UTC ( [id://950957]=note: print w/replies, xml ) Need Help??


in reply to map and grep or clear code?

Like tobyink I think a regex solution is simpler and I would add the lower case letters to your look-up hash rather than uc'ing each letter or string in turn.

use strict; use warnings; use 5.010; my @lettersPerButton = ( 3, 3, 3, 3, 3, 4, 3, 4 ); my @buttons = map { ( $_ ) x shift @lettersPerButton } 2 .. + 9; my %filterMap = map { $_ => shift @buttons } q{A} .. q{Z}; $filterMap{ lc( $_ ) } = $filterMap{ $_ } for q{A} .. q{Z}; my @toClean = qw{ GAV18 gAv18 peter Bill34 }; foreach my $filterClean ( @toClean ) { ( my $filter = $filterClean ) =~ s{([A-Za-z])}{$filterMap{ $1 }}g; say qq{$filterClean --> $filter}; }

The output.

GAV18 --> 42818 gAv18 --> 42818 peter --> 73837 Bill34 --> 245534

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found