splitting into paras

Matthew Lawrence matthew.lawrence at ehsbrann.com
Wed Jan 11 15:18:54 GMT 2006


Robin Barker wrote:
>>@paras = split /(?:$crlf\s*){2,}/, $test;
> 
> 
> That will strip space (and tabs) from the first line of the paragraphs.
> 
> my $crlf = qr/\x0a\x0d?|\x0d\x0a?/;
> my @paras = split /(?:$crlf\s*)+$crlf/, $text;
> 
> or
> 
> my @paras = split /$crlf\s*$crlf/, $text;
> 
> ?

On the face of it the second one looks wrong, as it would fail with more
than 2 newlines, but the \s* will span multiple lines, so as long as all
of the possible $crlf matches also match \s, either of these will do.

Matt


More information about the london.pm mailing list