$/ 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |