Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Printing Table of Contents From an Array On Multiple Pages

by Milti (Acolyte)
on Jul 10, 2013 at 17:47 UTC ( #1043514=perlquestion: print w/ replies, xml ) Need Help??
Milti has asked for the wisdom of the Perl Monks concerning the following question:

Let's say I have a directory with 50 files in it. I use the Perl Glob function on the directory to get an array containing a list of the files.

Now I want to print the individual file names from the array onto a template (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?

Thanks for any help you can provide.

Comment on Printing Table of Contents From an Array On Multiple Pages
Re: Printing Table of Contents From an Array On Multiple Pages
by jeffa (Chancellor) on Jul 10, 2013 at 18:05 UTC
Re: Printing Table of Contents From an Array On Multiple Pages
by kcott (Abbot) on Jul 11, 2013 at 09:47 UTC

    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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-30 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls