Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Printing Table of Contents From an Array On Multiple Pages

by Milti (Sexton)
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

Replies are listed 'Best First'.
Re: Printing Table of Contents From an Array On Multiple Pages
by jeffa (Bishop) on Jul 10, 2013 at 18:05 UTC
Re: Printing Table of Contents From an Array On Multiple Pages
by kcott (Canon) 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?
[Corion]: Yeah (although their mother was somewhat stressed out regardless) - but it made for an otherwise relaxed evening ;)
[ambrus]: Corion: nice.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2016-12-08 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (139 votes). Check out past polls.