Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Spliting a file into an array using blank lines as delimiter

by dsb (Chaplain)
on Jan 24, 2001 at 20:06 UTC ( #54010=note: print w/replies, xml ) Need Help??


in reply to How do I split a file into an array using blank lines as delimiter

your code would work but the pattern you have '$string' splitting on is no good. Right now you have it matching any line with 0 or more whitespaces at the beginning. That's every line. Try this:
open (LOG,"Messages.log"); while (<LOG>){ $string .= $_; } @array = split(/\n{2,}/, $string); # note the new pattern

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2021-05-12 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (127 votes). Check out past polls.

    Notices?