Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Finishing Touches

by Legg83 (Novice)
on Apr 01, 2001 at 11:05 UTC ( [id://68805]=perlquestion: print w/replies, xml ) Need Help??

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

I have my script almost near completion. There are two features that I would love to add, but haven't the slightest idea on where to begin.

One, the easiest, I am assuming, is a simple alaphabetazier. Even though I don't know how to spell, I want to be able to take @business.. catagagorize it by alaphabetizied name, and then display the results. If I could just find a function to sort by logical alaphabet or something, i'm sure i could find out how to do the rest.

next.. i have all my data stored in text files.. so I am not using a fancy SQL database server for anything. I would like to add, to my html pages.. an option that says "show next 10 results", and an option that says "show last 10 results".. maybe even go through the trouble of having page numbers, just something so that I can take my database and display it in small quantities.

thanks monks

Replies are listed 'Best First'.
Re: Finishing Touches
by nashdj (Friar) on Apr 01, 2001 at 11:34 UTC
    Well sorting alphabetically is easy, even a simple search on perlmonks can tell you how to do that. I can even give you the node: How do I sort something alphabetically?

    For your result grouping, if you always load the entire file into an array on each page load you can simply do something like
    my $start = (get starting number from your input); for ($start..$start+10) { (do things with $array[$_]); }
    You'll have to set it up so that the first time the results are displayed it starts with 0. Then on each page load set the next 10 and previous 10 links to pass paramaters back to be used in $start as $start + 10; or $start - 10;

    Oh, also you'll probably want to throw something in to break out of the loop if $_ becomes greater than the size of the array.

    I havent really answered your question explicitly, as I got the idea that you just wanted a start, and would sort out the gory stuff yourself :)
Re: Finishing Touches
by nysus (Parson) on Apr 01, 2001 at 12:51 UTC
    I'm not sure what you mean to sort by "logical alphabet", but one common way of sorting an array is:
    @array = ('george', 'mike', 'steve', 'ray', 'paul', 'brian', 'peter', +'amos'); @sorted = sort @array;
    This above will set @sorted to: amos, brian, george, mike, paul, peter, ray, steve. Note this will place the items in ascii order so if you have numbers in the array, like '7892 and '92', '7892' would actually come before '92' because '7' comes before '9'. To place things in numerical order, you would use
    @sorted = sort {$a <=> $b } @array;

    The first thing that pops into my head for the second half of your question is to create a script that will generate an html page for each group of 10 files. This will give users the ability to jump form page to page randomly as well as sequentially.

    Hope this helps.

      This is sorting ASCIIbetically rather than alphabetically. What you need is:
      @sorted = sort { lc(a) cmp lc($b); } @array;
      I'm sure this was covered elsewhere recently...

      cLive ;-)

        oops, just noticed - should be ($a), not (a). sometims i ttype too quick...
Re: Finishing Touches
by lachoy (Parson) on Apr 01, 2001 at 17:25 UTC

    Others have covered the sorting, but you might want to take a look at HTML::Pager for displaying the entries you want per page. Also, depending on your data you could find the DBD::CSV or DBD::RAM modules helpful, particularly since both allow you to execute queries on data stored in a text-only format.

    Chris
    M-x auto-bs-mode

    (update: fixed DBD::RAM link - doh!)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found