Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Printing Table of Contents From an Array On Multiple Pages

by Milti (Beadle)
on Jul 10, 2013 at 17:47 UTC ( [id://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 (Archbishop) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-09-08 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.