http://www.perlmonks.org?node_id=950920

ghenry has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm trying to see which is easier for maint. I have the following and wondering if I should replace it with map and grep. Not sure why, but find myself not reaching for them ever. This turns letters on your phone dialpad to numbers:

use strict; use warnings; use 5.10.1; my $filter_clean = 'GAV18'; my %filter_map = ( A => 2, B => 2, C => 2, D => 3, E => 3, F => 3, G => 4, H => 4, I => 4, J => 5, K => 5, L => 5, M => 6, N => 6, O => 6, P => 7, Q => 7, R => 7, S => 7, T => 8, U => 8, V => 8, W => 9, X => 9, Y => 9, Z => 9, ); # 1st version my $filter = q{}; if ($filter_clean) { my @filter_split = split //, $filter_clean; for my $fc (@filter_split) { if ( $fc =~ /\d/ ) { $filter .= $fc; } else { $filter .= $filter_map{ uc $fc }; } } } say $filter; # 2nd version. Why would I use below (when it's working right, that is +) over above? $filter .= map { $filter_map{ uc $_ } } grep { !/\d/ and $filter_clean } split//, $filter_clean; say $filter; [ghenry@linux]$ perl t/map.pl 42818 428183

I also need to make this work properly so I'm not returning the amount of matches grep has.

Advice? I prefer my first version for when I come back later.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!