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.