[Israel.pm] using split and join to add a characters every 2 original ones

Yossi Itzkovich Yossi.Itzkovich at ecitele.com
Sun Nov 2 05:48:07 PST 2008


I was asked by a friend to write a one-linear to add a character every 2 characters.  For example:
"For example" Will become "Fo#r #ex#am#pl#e"

I tried to do it with join and split (seems natural for me), but had no success, I managed to do it only with map:

The best I got from join and split is :
join ("#" , split (/(..)/, $_))
which prints 2 #  after each 2 characters. I understand why, but I could not get rid of it.

Any ideas ?


More information about the Perl mailing list