Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Split on Blank Line into array, and keep the blank line in the array

by linuxer (Deacon)
on May 22, 2009 at 22:15 UTC ( #765765=note: print w/ replies, xml ) Need Help??


in reply to Split on Blank Line into array, and keep the blank line in the array

Please use code tags. See Markup in the Monastery for details.

How do you want to treat the blank lines?

Maybe you need to read blockwise?

#!/usr/bin/perl -l use strict; use warnings; { local $/ = ""; my @blocks = <DATA>; local $, = "\n"; print map { ">>>$_<<<" } @blocks; } __DATA__ AB A BB CC C CD EE EA

Maybe you want to capture the split pattern?

#!/usr/bin/perl -l use strict; use warnings; my $content = do { local $/; <DATA> }; my @blocks = split /(\n\n+)/, $content; { local $, = "\n"; print map { ">>>$_<<<" } @blocks; } __DATA__ AB A BB CC C CD EE EA


Comment on Re: Split on Blank Line into array, and keep the blank line in the array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-09-01 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (14 votes), past polls