[Wellington-pm] I must be stupid...

Brenda Wallace brenda at wallace.net.nz
Tue May 5 15:08:49 PDT 2009


I think you want a g on the end of the regex to make it greedy.

On 5/05/2009, at 22:48, Andrew McMillan <andrew at morphoss.com> wrote:

> ... but you probably already knew that :-)
>
> Can someone please explain to me why I get a difference between these:
>
>  $text =~ s/\s+/ /s;
>
> vs.
>
>  $text = join( ' ', split( /\s+/s, $text) );
>
> Assuming that $text is a multi-line string beforehand, and I want it  
> to
> be a single-line string afterwards.
>
> The first one doesn't do what I want - to replace sequences of
> whitespace (including newlines) with a single space.  The second seems
> remarkably long-winded to achieve what I want, and quite probably less
> efficient than one might hope, as well.
>
> I expect that I am missing something blindingly obvious, and an
> explanation will no doubt assist my progress along the path to perl
> enlightenment.
>
> Yours,
>                Confused.
>
> --- 
> ---------------------------------------------------------------------
> andrew (AT) morphoss (DOT) com                             
> +64(272)DEBIAN
>    I have not seen high-discipline processes succeed in commercial
>                     settings. - Alistair Cockburn
>
> --- 
> ---------------------------------------------------------------------
>
>
> _______________________________________________
> Wellington-pm mailing list
> Wellington-pm at pm.org
> http://mail.pm.org/mailman/listinfo/wellington-pm


More information about the Wellington-pm mailing list