Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to split into paragraphs?

by Samy_rio (Vicar)
on Nov 16, 2006 at 05:22 UTC ( #584373=note: print w/ replies, xml ) Need Help??


in reply to How to split into paragraphs?

Hi jrw, this may help you if I understood your question correctly.

use strict; use warnings; my $str; while (<DATA>){ chomp; ($_ =~ m/^\w/) ? ($str .= "<\/p>\n<p>$_\n") :($str.="$_\n"); } $str =~ s/^(<\/p>)(.+)$/$2$1/gsi; print $str; __DATA__ abc: asdf1 asdf2 def: asdf3 ghi: asdf4 asdf5

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';


Comment on Re: How to split into paragraphs?
Select or Download Code
Re^2: How to split into paragraphs?
by jrw (Scribe) on Nov 16, 2006 at 12:22 UTC
    Velusamy, see clarification above. I already have the entire string in a variable and want to split it into substrings.

      Try like this,

      use strict; use warnings; my $str = <<EOF; abc: asdf1 asdf2 def: asdf3 ghi: asdf4 asdf5 EOF my @str = split/(?=\n+\w)/, $str; print "$_" for @str; #or $str =~ s/(^|\n+)(\w)/$1<\/p>\n<p>$2/gsi; $str =~ s/^(<\/p>)\n*(.+)$/$2$1/gsi; print $str;

      Regards,
      Velusamy R.


      eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://584373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2015-07-07 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls