Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Perl won't do this for you automatically, you have to program it. I agree with chadys advice, storing the entries in a database of some sort would be better than just storing the html.

anyways, here's what you can do with your version of the program:

You need to keep track of when it's time to write a new file. That means you need a counter of some sort. You'll have to store the counter in a different file again, maybe counter.txt.

open(C, "counter.txt") and $c = <C> and close C and $c++; open(C, ">counter.txt") and print C $c and close C;

Let's say you want to start a new file every time the counter reaches a multiple of 10. You might call the files that contain the html "view0.htm" for the first 10 entries, "view1.htm" for the next 10, and so on.

$fileno = int($c / 10); $filename = "view" . $fileno . ".htm"; open(DASH,">>$filename"); print DASH "print the entry here"; close DASH

That's almost all. If you want to have Links from one page of the guestbook to the next, you have two options: do it in HTML, with frames (yuck, I hate frames) or write the links into the view*.htm files. Putting the "back" at the top of each page:

if (int($c / 10) == $fileno ) { # this is the first time we write to this # file, because $c is 10 or 20 or 30 or ... # link back to the one before print DASH "<a href=view" . ($fileno-1) . ".htm>Back</a>"; }
and the "Next" link at the bottom is probably the easiest:
if ( $c % 10 == 9 ) { # this is the last time we write to this # file, because $c is 9 or 19 or 29 or 39 or ... # link on to the next one print DASH "<a href=view" . ($fileno+1) . ".htm>Next</a>"; }

Assembling these code snippets in the right order is left as an exercise to the student ;-)

--
Brigitte    'I never met a chocolate I didnt like'    Jellinek
http://www.horus.com/~bjelli/         http://perlwelt.horus.at

In reply to Splitting stuff into many pages with back and next buttons - (Was: Max Submissions?) by bjelli
in thread Max Submissions? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-24 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found