Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

was wondering if there is any Perl module that allows the generation of a list of names (an array full of names for example) to be displayed neatly in a HTML.

The list of names include 200 names and may grow to 500-600 in a few years.

I want to allow users to be able to search a particular name a easy way. I already have a search function but now want a page to list all names and probably best sorted alphabetically. So perhaps a module that generates a table of content type of page where a user can click on "A" and it'll jump to the A index, etc etc.

thanks
  • Comment on generating a large list of names to be displayed neatly in HTML

Replies are listed 'Best First'.
Re: generating a large list of names to be displayed neatly in HTML
by nedals (Deacon) on Sep 01, 2006 at 21:06 UTC

    The easiest way is to use HTML::Template
    Check out the LOOP function.

    You will need to organize your data into an AoH. Then simply pass a AoH reference to the template.

Re: generating a large list of names to be displayed neatly in HTML
by swampyankee (Parson) on Sep 01, 2006 at 20:34 UTC

    Sounds like a job for templates...you could look in template.

    emc

    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Albert Einstein
Re: generating a large list of names to be displayed neatly in HTML
by NetWallah (Canon) on Sep 01, 2006 at 22:39 UTC
    In addition to the formatting suggestions above, your generated web page could advise the user to use the browser's SEARCH function, typically invoked by CTRL-F, to search for the name (It will search for any text on the page).

         "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

Re: generating a large list of names to be displayed neatly in HTML
by TedPride (Priest) on Sep 02, 2006 at 22:30 UTC
    A raw list in alphabetic order is probably fine. They can use the find function on their browser to locate things from there. However, if you -really- want a list that you can jump around in by letter:
    use strict; use warnings; my (@names, $f, %names); chomp (@names = <DATA>); for (@names) { $f = substr($_, 0, 1); push @{$names{$f}}, $_; } print join ', ', map { "<a href=\"#$_\">$_</a>" } sort keys %names; print "<p>\n\n"; for (sort keys %names) { print "<a name=\"$_\"></a><b>$_</b>\n<ul>"; print join "\n", map { "<li>$_" } sort @{$names{$_}}; print "</ul><p>\n\n"; } __DATA__ Alvin Clarissa Kappa Bob Bubba Zim
    There's probably a CSS way to make it so just pressing a key on the keyboard jumps to that letter, but I'm not going to complicate things.
Re: generating a large list of names to be displayed neatly in HTML
by ww (Archbishop) on Sep 03, 2006 at 23:59 UTC
    or use an html solution...at the top of your page ouput code, create:
    <a href="#a">A</a> | <a href="b">B</a> | etc....
    and, at the appropriate points in your list ouput, have your script insert
    <a name="a"> Alice Andrew Aunt Samatha <a name="b"> Bruce <a name="c"> Carol Chuck ...
    et cetera....