in reply to How to split into paragraphs?
Try setting $/ = '';.
#! perl -slw use strict; $/ = ''; # paragraph mode print "'$_'" while <DATA>; __DATA__ abc: asdf1 asdf2 def: asdf3 ghi: asdf4 asdf5
Prints
c:\test>junk 'abc: asdf1 asdf2 ' 'def: asdf3 ' 'ghi: asdf4 asdf5 '
Setting $/ = "\n\n"; would also work for your data if there is exactly one 'blank line' between the paragraphs, but the magical setting of $/ = ''; is more flexible.
Note this quote from perlvar
Setting it to "\n\n" means something slightly different than setting to "", if the file contains consecutive empty lines. Setting to "" will treat two or more consecutive empty lines as a single empty line. Setting to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to split into paragraphs?
by jrw (Monk) on Nov 16, 2006 at 12:27 UTC | |
by BrowserUk (Patriarch) on Nov 16, 2006 at 12:39 UTC |