Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Printing Table of Contents From an Array On Multiple Pages

by kcott (Abbot)
on Jul 11, 2013 at 09:47 UTC ( #1043675=note: print w/ replies, xml ) Need Help??


in reply to Printing Table of Contents From an Array On Multiple Pages

G'day Milti,

"... (I know how to do that) but wish to limit the number of items per page to 10 while including a footer saying next page or whatever. How do I do that?"

The logic for that is fairly straightforward. Using less filenames and shorter pages for demo purposes:

$ perl -Mstrict -Mwarnings -E ' my @files = "A" .. "J"; my $items_per_page = 3; my $current_item = 0; for (@files) { say; if (not ++$current_item % $items_per_page) { say "Next Page" unless $current_item == @files; } } ' A B C Next Page D E F Next Page G H I Next Page J

In case you were wondering, 'unless $current_item == @files' stops the "Next Page" message being output when the end of page coincides with the end of data. Using one less file:

$ perl -Mstrict -Mwarnings -E ' my @files = "A" .. "I"; my $items_per_page = 3; my $current_item = 0; for (@files) { say; if (not ++$current_item % $items_per_page) { say "Next Page" unless $current_item == @files; } } ' A B C Next Page D E F Next Page G H I

-- Ken


Comment on Re: Printing Table of Contents From an Array On Multiple Pages
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-12-18 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls