Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: splitting up a long text at regular intervals

by ioannis (Vicar)
on Oct 31, 2005 at 00:40 UTC ( #504097=note: print w/ replies, xml ) Need Help??


in reply to splitting up a long text at regular intervals

Since preserving paragraphs is more important than exact linecount; this is about what you want: keep reading paragraphs, until they exceed a predefined number of lines.

use Fatal qw(open); use constant MAXLINES => 2; open my $i, 'data.txt'; (local $/, my ($sum, $buf)) = ( '', 0 , undef); while (<>) { $buf .= $_; $sum += tr /\n/\n/; next if $sum < MAXLINES ; print "$buf----------";; ($sum, $buf) = (0, undef ); }


Comment on Re: splitting up a long text at regular intervals
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2015-07-29 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls