Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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]: choroba: Ooof! I can imagine that ;)
[Corion]: I think at a Perl workshop some years ago I gave two talks on the same day and after that decided to only submit one talk per event ;)
[LanX]: you play the triangle, right?
[choroba]: just one of its angles, in fact
[LanX]: <|--
[choroba]: Reminds me of an old joke about an orchestra...
erix imagines that in a true Lancs accent
[choroba]: so a Czech orchestra rehearses a new piece by a German composer

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-03-27 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (319 votes). Check out past polls.