If you have a look at perlvar, in the $/ section, you have this:

$/ The input record separator, newline by default. This influences Perl's idea of what a "line" is. Works like awk's RS variable, including treating empty lines as a terminator if set to the null string. (An empty line cannot contain any spaces or tabs.) You may set it to a multi-character string to match a multi-character terminator, or to "undef" to read through the end of file. Set- ting it to "\n\n" means something slightly differ- ent than setting to "", if the file contains con- secutive 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.

So, if you set $/="" you'll get something similar to your needs (if I'm understanding what you need).

I would also recommend you to localize $/, so it will return to the previous value. So, you can surroud your paragraphs with tags with something like that:

#!/usr/bin/perl my @paras = do { local $/=""; <DATA> }; #Idiom localizing $/ for (@paras){ print "<html paragraph>\n"; print $_; print "</html paragraph>\n"; } __DATA__ This is the first paragraph of text. This is the second. This is also the second. This is the 3rd.

P.D.: You should read Writeup Formatting Tips, please put code tags around your code.


In reply to Re: matching paragraphs by deibyz
in thread matching paragraphs by imhotep

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.