Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Supressing page breaks in format/write output

by yaconsult (Acolyte)
on May 29, 2009 at 01:10 UTC ( #766785=perlquestion: print w/replies, xml ) Need Help??

yaconsult has asked for the wisdom of the Perl Monks concerning the following question:

I thought I could eliminate the page breaks in a form by setting $= to a large number, like 200. The form will be viewed using a browser and can be scrolled so I don't want or need page breaks and multiple copies of the header. How do I get rid of them?

Maybe the problem is where in the code I have to set $=. Do I have to set it again after every write?

Let me add the following repsonse to a subpost to the root post to make it clearer. I apologize for muddying the waters by using the word "form" in my original post. I have updated the post title to more accurately reflect the question.

The output is NOT a web page. It is a simple text file. It gets emailed to people via a script.

Coincidentally, there is a web page somewhere that, when a link is clicked on it, displays the contents of this simple text file with columns of data in the browser.

The only problem is that the text gets broken into "pages" when there are many lines and I don't want it to.

2009-03-15 04 143 oconnorn
^L Date Hour Requests UID
2009-03-15 04 121 rdreyer

That is what happens every so many lines - a ^L and a reprinting of the header. I just want those breaks and header repeats to disappear.

  • Comment on Supressing page breaks in format/write output

Replies are listed 'Best First'.
Re: Supressing page breaks in forms
by Albannach (Monsignor) on May 29, 2009 at 01:56 UTC
    Have you tried setting $- (number of lines left on the current page) to a suitably large number after each write instead?

    Update Since there seems to be some question as to whether my suggestion would work, I did the following test:

    use strict; use warnings; $= = 5; for(1..15) { write; #$- = 999; } format STDOUT = @### @###### @### $_, $_**2, $- . format STDOUT_TOP = ---TOP--- . __END__
    If I run the above, I get the following at the console:
      The excerpt below is doing the write. The array has about 260 elements. At line 60, a control-L and header repeat are printed, so clearly, I'm not setting the number of lines remaining the way I want to. To avoid confusion about special variables, I'm using the English module to be clear about what I'm setting.
      foreach my $line (@top_users_results) { ( $day, $hour, $count, $uid ) = split( ",", $line ); $hour = substr( $hour, 0, 5 ); $hits_total += $count; write TOPUSERS_COUNTS; $FORMAT_LINES_LEFT = 999; }
Re: Supressing page breaks in forms
by akho (Hermit) on May 29, 2009 at 11:14 UTC
    You should not use formats at all, especially to generate web pages. There are lots of adequate templating solutions on CPAN; please consider using Template or HTML::Template.
Re: Supressing page breaks in forms
by ww (Archbishop) on May 29, 2009 at 10:24 UTC

    This begs further explanation.

    • What is the "form?" (a web page, .pdf or ???)
    • How are you creating the "form?" (a templating module, 'by hand' or ???)

    These might give us some hints about why you feel the need to suppress multiple headers and page breaks.

    In general, pages designed for viewing in a browser (.pdf excepted) do NOT utilize "page breaks" and creating a "form" (meaning something the viewer can fill-in and submit) requires specific markup. (afterthought: do you mean a "table" which presents data but which, in the common case, is not designed to facilitate viewer response?)

    So unless I'm missing something obvious (always possible this early in the am), the question -- as stated -- doesn't compute.

Re: Supressing page breaks in forms
by tbone1 (Monsignor) on May 29, 2009 at 13:26 UTC
    Are you writing to a file, a web page, a screen, an Oracle form, ... before it goes to a browswer? The answer really depends. Really, the best thing would be to just write the thing and not worry about the formatting. HTML and the browser are the right tools to do that. (Well, assuming you're not using IE6, of course.)

    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

      Sorry, I should have provided more detail.

      I am outputting nicely formatted text files with tables of data and statistics.

      These get emailed to people and are also available by going to report pages on web pages that contain statistics and reports.

      So all I want to do is not have page breaks inserted into my formatted output. In both email and on the web pages that people will see the columns of output, they can just scroll.

      So the problem simply is, how can I write out many lines of formatted output without having page breaks automatically inserted?

      I tried setting $- to 200 after each write, as suggested by Albannach above, but that doesn't seem to be doing the trick either. I'm still getting page breaks with headers repeats.

      This must be possible to do. If I were printing on legal-size paper instead of letter, I'd want more lines on the page between breaks. How can I set the number of lines in the output I'm generating with format/write?

        $- is the number of lines left to print for the default file handle. Does resetting it change anything? $=, on the other hand, is the current page length for the default file handle. You could try setting $= to something absolutely massive (5000?) depending on the data. You would need to know and understand the data to come up with a suitable value. Have tried setting it to undef? Just a (dangerous) thought.

        tbone1, YAPS (Yet Another Perl Schlub)
        And remember, if he succeeds, so what.
        - Chick McGee

        <Update: Root Node has been revised since this was posted /update>

        Let me repeat: web pages do NOT have intrinsic page breaks. When printed to dead trees, the print routine inserts them, but when viewed on a monitor they have no need to paginate.

        Think of the rendered web page as appearing on a long (very long!) roll of paper, with each end attached to a roller, viewed through a window frame. Scrolling moves the paper (use "vertically" for your mental model); changes which portion of the text you can see. Web pages are NOT analagous to cut sheets of paper, be those 8.5x11, A4, Legal, or 6 inches wide by a mile high.

        So, assuming your "nicely formatted text files" are, indeed, pure text and not some form of word-processing format, you need do no more than this:

        You can practically use the content above as an element of a home-brew templating system. The step-by-step below is sub-optimal, but should work until you learn more about html, perl, and the templating systems cited in previous responses.

        1. Save the template above to a local file.
        2. Read (see open among others) the template into a variable in your script).
        3. Read the "nicely formatted text" into another variable.
        4. Use substitution (see perlretut) on the first variable to replace the content above between ** and ** with the contents of your second variable.
        5. Hand tweak the <meta....>s above, replacing the ##...## with appropriate content, or remove them before step one if you're not worried about search engine rankings.
        6. Write (see"open" above and perldoc -f print) the modified second variable to a file, name.htm.
        7. Move or copy the name.htm to a web server (if some viewers will be on-line) or simply distribute it to interested parties as an attachment to email, by sneaker net or whatever.

        There will be no page breaks. And, FWIW, you can simply paste (remember, we're assuming your source files are truly pure "text," not word processor documents, .pdfs, Latex, or some other format using markup) the source document into an email to distribute it. Same deal: no page breaks.

        If, however, your source file is a wp document, note that wp documents do, typically, contain page break codes. You may have to remove those. But you will also have a strip whatever markup the creator_application inserted to organize the tables and then recreate those with .html or even .xml markup (for which, you'll need to spend a few minutes learning the fundamentals).

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://766785]
Approved by Albannach
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-05-17 07:47 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (65 votes). Check out past polls.