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

First I'd like to say that I'm kind of new to programming but learning fast and am looking for information anywhere I can find it.This is kind of a long question but here goes. How does one, say, in a guest book limit the number of entries per page and number the pages, and at the same time alternate the back ground color between entries? Another version of the same question-I've seen image galleries where the number of images per row are limited as to how many images as well as how many rows per page before moving on the next page???I have seen different forums and image galleries and have read through the code behind some of them but for some reason or other I can't seem to put my finger on some type of syntax for this. I have even read books on perl and the answer is probably right in front of me but my eyes need opened to whatever it is I'm missing. Any/all help/guidance/insight would really be greatly appreciated. While I'm on a roll with the questions what is the syntax for eliminating a string from form input-namely "http://www." in a input type="text"name="url" situation. I've been able to figure out lots of information on perl programming from reading and the price of schooling is really out of the question. Thanx, Dave dave@godhears.com

Replies are listed 'Best First'.
Re: Syntax Questions
by dragonchild (Archbishop) on Apr 22, 2003 at 20:26 UTC
    You're not asking the right questions.

    How does one, say, in a guest book limit the number of entries per page and number the pages, and at the same time alternate the back ground color between entries?

    That is really asking "How do I do XYZ at a given point in a list of stuff?"

    what is the syntax for eliminating a string from form input-namely "http://www." in a input type="text"name="url" situation.

    That is really asking "How do I remove a substring from another string?"

    You're too focused on your actual task to be able to learn the general principles. Take a step back and build slowly. Take some baby steps. Maybe, instead of working with the web, work in ASCII. Try running the following program:

    use strict; my @array = 1 .. 10; my $num_per_row = 4; foreach my $i (0 .. $#array) { print $array[$i], ' '; print "\n" unless ($i + 1) % $num_per_row; } print "\n";
    Use the principles in that program to do that image gallery thing.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Syntax Questions
by demerphq (Chancellor) on Apr 22, 2003 at 21:42 UTC

    First I'd like to say that I'm kind of new to programming but learning fast and am looking for information anywhere I can find it.

    The first part is great the second part isn't. Don't take whatever information you can find. A bunch of it will be crap and then you'll end up here asking us questions we've seen a hundred times which wont be fun for any of us.

    Having said that you are in good hands here. Learn a bit more about the site and how to get maximum advantage out of it (which actually involves contributing yourself, but we'll leave that for later) and I promise you'll learn tons, and fast.

    This is kind of a long question but here goes.

    Yup theres goes your readers. Or at least most of them. You just posted about 100 to 200 words in a format that doesnt respect or contain whitespace. Which means that a big chunk of your readers just saw an amorphous blob of color and then ran away as fast as they could.

    PM (thats PerlMonks BTW) offers a lot of good ways to mark up your posts (we call em nodes) so that you can be easily understood. For instance there are <code> tags, which we use to make sure that our code displays the way we see it in the textbox (with a few features). But you didnt post any code so you might have missed that one. :-)

    Anyway, the point here is that most people arent going to put a lot of energy into figuring out badly communicated problems. And they certainly arent going to extract them from the text like perls from an oyster. Especially not when they cant even see the problem as there isn't any code. (Notice a running theme here? ;-)

    How does one, say, in a guest book limit the number of entries per page and number the pages, and at the same time alternate the back ground color between entries?

    Theres lots of ways. But im not just going to guess which will make sense to you. I need to see your code, how you _think_ it should work, and then I can point you in a better/different direction. BTW, I suggest you go and look at the stuff at NMS, I see that they have a guestbook there that you can download. You could review that for style, and coding examples. You could come back and post little snippets that you cant figure out and well try to explain them. But without code we cant do much.

    Another version of the same question-I've seen image galleries where the number of images per row are limited as to how many images as well as how many rows per page before moving on the next page??? I have seen different forums and image galleries and have read through the code behind some of them but for some reason or other I can't seem to put my finger on some type of syntax for this.I have even read books on perl and the answer is probably right in front of me but my eyes need opened to whatever it is I'm missing.

    We cant help you without code. And I dont think you can help yourself without being able to clearly explain what your objective is. So you have a bunch of images. And exactly what do you want to do with them? Order them in some way how? What you've given isnt a meaning description (to me anyway.)

    Theres a great line from Apollo 11: "Work the problem people, work the problem." As in break the problem into chunks that are smaller and smaller and eventually you are left with a lot of tiny chunks that you can understand. Then put them back together. When some of the code doesnt do what you would expect, come back and ask us about it.

    Any/all help/guidance/insight would really be greatly appreciated.

    Hopefully my comments give you an insight into how to tap into the fantastic wealth of information that is here. Read the nodes. Use Super Search. Ask more pointed questions. Post. Code.

    While I'm on a roll with the questions what is the syntax for eliminating a string from form input-namely "http://www." in a input type="text"name="url" situation.

    You might use a regex. But on what is a different question. Theres a zillion snippets here that do stuff like that. Search in the index for merlyn's stuff, i know theres stuff in there that would be useful to you.

    I've been able to figure out lots of information on perl programming from reading and the price of schooling is really out of the question.

    Theres lots of excellent free material out there, and theres lots of good books. I suggest anything by merlyn or by thedamian. The tutorials that come with the perl distirbution (the Win32 AS release come with them in HTML and indexed form) are excellent. The tutorials here are excellent. Just reading Seekers Of Perl Wisdom every day will teach you tons.

    Thanx,

    No prob. I hope you actually post a second time dude. :-)

    dave (at) godhears.com

    Little tip. Dont put your email at the bottom of posts. At least not like that. A lot of people come here and post expecting us to actually email them solutions to their problems. Its unlikely to happen to put it mildly. If you really want the spambots to read your email then put it in something that is identifiable as a signature. That way nobody will just ignore your mail thinking you had tried it on.

    Some links for you to peruse:

    HTH


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: Syntax Questions
by perlguy (Deacon) on Apr 22, 2003 at 20:28 UTC

    First off, I understand your excitement and anxieties here, but you really need to show us some of your code fragments so that we can lead you in the right direction. I believe many of us here have the capability of answering your question(s), but we don't have time to write an entire application.

    Post a little code, and watch the magic unfold.

Re: Syntax Questions
by valdez (Monsignor) on Apr 22, 2003 at 20:32 UTC

    What you described is exactly what lead me to learn Perl and the Monastery is the right place to ask for guidance. The best way to obtain an answer is to show some code; so, please, don't be shy, show us your attempts :)

    Ciao, Valerio

Re: Syntax Questions
by Coplan (Pilgrim) on Apr 22, 2003 at 20:47 UTC
    Well, your question is a very broad question. Not knowing anything about your setup, all I can do is give a general response. If you want something more specific, it'd be best to include that when asking the monks for help.

    Again, I have to be very broad here. I don't know if you're pulling from a database, or a text file, or what. If I were to pull from a database, I'd be using indexes and limits. I would run an SQL query such as this:

    SELECT Title, Entry, Author FROM GBook ORDER BY SubDate LIMIT 0, 10

    In such a case, that means we're selecting 10 records starting at record #1 (I could have those numbers reversed). Then all I would have to do is keep track of what number to start on, and you can generate the previous/next based on that.

    Anyhow, making each row a different color is also a matter of keeping track of what's going on. You might want to have a test to check what row its on. Even rows should get printed in one color, odd rows in another.