Ricardo SIGNES wrote:
* Cinzia Sala <[EMAIL PROTECTED]> [2004-07-07T09:35:42]
I would like to transform a string like :
MSDDIDWLHSRRGVCK
in a identical string, but with two spaces between each letter:
You wouldn't use tr/// for this. There are two simple ways:
$string =~ s/(.)(?!\Z)/$1 /g;
# replace any char /not/ followed by end-of-string with itself and a
# space
or
$string = join(' ', split('', $string));
# split $string into individual characters
# then rejoin them with two spaces between them
consult "perldoc -f split" and "perldoc -f join" for the latter one.
or
$string =~ s/(?<!^)(?=[a-z])/ /gi;
# Insert two spaces where the next character is a letter (case insensitive)
# and the previous is *not* start of string
--
Flemming Greve Skovengaard The prophecy of the holy Norns
a.k.a Greven, TuxPower the world is doomed to die
<[EMAIL PROTECTED]> fire in the sky
4112.38 BogoMIPS the end is coming soon
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>