splitting into paras

Robin Barker Robin.Barker at npl.co.uk
Wed Jan 11 12:00:59 GMT 2006

> @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;


my @paras = split /$crlf\s*$crlf/, $text;



-----Original Message-----
From: Matthew Lawrence [mailto:matthew.lawrence at ehsbrann.com]
Sent: 11 January 2006 11:40
To: London.pm Perl M[ou]ngers
Subject: Re: splitting into paras

Simon Wistow wrote:
> For what it's worht this no seems to liberally accept all manner of crap 
> input
> my $crlf = qr/\x0a\x0d|\x0d\x0a|\x0a|\x0d/;
> my @paras = split /(?:$crlf\s*)/, $text;

Won't that produce 6 paragraphs for your original example instead of the
3 you were after?

@paras = split /(?:$crlf\s*){2,}/, $test;


This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Serco House, 16 Bartley Wood Business Park,
                   Hook, Hampshire, United Kingdom  RG27 9UY

More information about the london.pm mailing list