On 01/07/2013 12:41 PM, Andy Bach wrote:
On Thu, Jan 3, 2013 at 3:37 AM, Hamann, T.D. <thomas.ham...@naturalis.nl>wrote:

and then using a second regular expression to remove the space, but
that somehow seems silly. Surely there is a quicker way to do this?

s/(i)(\d\d)(o)/1${2}0/;


One route, esp. if there might be more letter<->number pairs (like "leet"
(e.g. as "1337") or a list of common numeric typos, maybe) is to use the
'/e' modifier and a lookup table:
my %leet_pairs = (
     i => 1,
     o => 0,
      e => 3,
);
s/(\w)(\d{2})(\w)/$leet_pairs{$1} . $2 . $leet_pairs{$3}/e;

a good idea but there is no need for the /e modifier. just make the replacement a string which is doable with what you have there.

        s/(\w)(\d{2})(\w)/$leet_pairs{$1}$2$leet_pairs{$3}/;

remember, the replacement part of s/// is just a double quotish string (with some special cases i won't cover here).

uri



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to