And now, thanks to perl, I can easily solve a problem that was too much bother to deal with before...
Internet guitar tab is the bastard child of ASCII art and musical notation. It looks like this, and as you can see, it's most undesirable to have a page break in the middle of a line of tab (which consists of 6 or more lines of text).
So I wrote this script to prevent paragraphs from spanning a page break. Perhaps someone's done this before but I figured it would be good practice... what do you guys think?
#!/usr/bin/perl -w use strict; use constant LPP => 63; # for enscript my @chunk = (); my $line = 0; while (<>) { if (/^\s*$/) { &printchunk; ++$line; print; } else { push @chunk,$_; } } &printchunk; sub printchunk { if (@chunk + $line >= LPP) { print "\n" while $line++ < LPP; $line = 0; } $line += @chunk; print @chunk; @chunk = (); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: page break at paragraph break
by dewey (Pilgrim) on Jul 28, 2007 at 23:27 UTC | |
by dbw (Beadle) on Jul 29, 2007 at 02:41 UTC | |
Re: page break at paragraph break
by SuicideJunkie (Vicar) on Jul 31, 2007 at 14:10 UTC | |
Re: page break at paragraph break
by jwkrahn (Abbot) on Jul 30, 2007 at 04:57 UTC | |
by dbw (Beadle) on Jul 31, 2007 at 14:52 UTC |