Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 pondering the Monastery: (7)
As of 2014-12-28 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls