in reply to Replacing double spaces (was: Reaplcing double spaces)

Here's my favorite way of doing that. The line is assumed in $_:

join '|', split " ", $_;
Double-quoted space is magical in split. It eats all whitespace.

Update: Bah:<code> join '|', split /\s\s/, $_; <code>

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Reaplcing double spaces
by CubicSpline (Friar) on Sep 23, 2001 at 06:51 UTC
    I did not fully comprehend what was happening when using " " or ' ' with split. It does indeed use any whitespace ( , \n, \t, \r ) as delimiters. Which made me wonder how you get it for just a single space. Most of you probably know this, but in case someone else was wondering too:

    split / /, $_;