Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: map and grep or clear code?

by brx (Pilgrim)
on Jan 31, 2012 at 18:59 UTC ( [id://951042]=note: print w/replies, xml ) Need Help??


in reply to Re: map and grep or clear code?
in thread map and grep or clear code?

No need to extend the hash (with 0..9) :
(my $output = $filter_clean) =~ s{ (\D) }{ $filter_map{uc $1} }exg;
If the aim isn't to separate data and function :
use strict; use warnings; use 5.10.1; my $filter_clean = 'GaV18'; sub filter2num { local $_=shift; s/[ABC] /2/igx; s/[DEF] /3/igx; s/[GHI] /4/igx; s/[JKL] /5/igx; s/[MNO] /6/igx; s/[PQRS]/7/igx; s/[TUV] /8/igx; s/[WXYZ]/9/igx; return $_; } say filter2num($filter_clean);

Replies are listed 'Best First'.
Re^3: map and grep or clear code?
by tobyink (Canon) on Jan 31, 2012 at 19:16 UTC

    Even something like:

    $filter_clean =~ tr/A-Z/22233344455566677778889999/;

    ought to do.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found