Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:48:28+00:00 2026-06-11T19:48:28+00:00

I want to extract the paragraphs from a text variable that retrieved from the

  • 0

I want to extract the paragraphs from a text variable that retrieved from the DB.

for extracting the pargaphs from file handler i use the below code :

local $/ = undef;
@paragarphs =<STDIN> 

what is the best option to extract paragraphs from a text variable using perl and if there are module on cpan that do this type of task ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:48:30+00:00Added an answer on June 11, 2026 at 7:48 pm

    You’re almost there. Setting $/ to undef will slurp in the entire text in one go.

    What you want is local $/ = ""; to enable paragraph mode, as per perldoc perlvar (emphasis my own):

    $/

    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. 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.


    Of course, it is possible to get a filehandle to read from a string instead of a file:

    use strict;
    use warnings;
    use autodie;
    
    my $text = <<TEXT;
    This is a paragraph.
    
    Here's another one that 
    spans over multiple lines.
    
    Last paragraph
    TEXT
    
    local $/ = "";
    open my $fh, '<', \$text;
    
    while ( <$fh> ) {
    
        print "New Paragraph: $_";
    }
    
    close $fh;
    

    Output

    New Paragraph: This is a paragraph.
    
    New Paragraph: Here's another one that
    spans over multiple lines.
    
    New Paragraph: Last paragraph
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extract the file name 13572_BranchInformationReport_2012-06-28.zip from the following text - 1:30,/icons/def13572_BranchInformationReport_2012-06-28.zip,13572_BranchInformationReport_2012-06-28.zip,0,184296,Jun
I want to extract text from crawled html web pages. I am using the
I want to extract variables from math expression using c#. I wrote this code
I want to extract text contents from GUI apps,here are 2 examples:: example 1:
I want to extract the background from this CSS and then use it to
I am new to lxml and want to extract <p>PARAGRAPHS</p> and <li>PARAGRAPHS</li> from a
I want to extract different content from a PDF file in Java: The complete
I want to extract attributes out of the xml file using this code xml
I want extract the path of images from a html page using PHP-preg_match_all(), the
I want to extract word after first 'from' in the following string- anti-CD24 from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.