in reply to Re^2: Could you look over my completed (but not working) short .cgi script?
in thread Could you look over my completed (but not working) short .cgi script?

Ugh. This is really difficult for me too. It would be so easy for me to "spill the beans". But given this is an assignment. I can only point you toward the text that supplies you with the information you need to solve your problem. I gave you some other key words to search for, that would have armed you with the answers. Let me just suggest that quoting really is the key here. As is interpolation. If you continue down the page I gave you in the "reading assignment", and read the section "Gory details of parsing quoted constructs". You should also find clues to what you've done incorrectly. While doing so, think quoting quotes. That may help you discover what you need to know.

Best wishes.

--Chris

¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

  • Comment on Re^3: Could you look over my completed (but not working) short .cgi script?

Replies are listed 'Best First'.
Re^4: Could you look over my completed (but not working) short .cgi script?
by StarRice (Novice) on May 31, 2014 at 07:18 UTC
    No worries! I actually got both of them working by trial and error. :) Seems like that's the one true way to fix things in programming, and of course reading. The document you linked me will be fun to read in my free time just to get the hang of Perl. Thanks a whole bunch. Now...for my foreach statement in the 2nd script, its not displaying properly the items saved in the cookie '$C_basket'. It's just a blank section. Is that correct? I was never good with the 'foreach/for/if' statements. (Shame on me, I know)

      StarRice:

      Actually, blind trial and error isn't a very good way to debug things.

      There are numerous rules that you'll have to follow to make a program work properly. As you're a new programmer, you're not familiar with them all, so trial and error is one of the ways you start discovering/learning those rules, but doing it blindly causes a few problems:

      1. You'll probably not know *why* it started working when it finally does
      2. You won't recognize broken pieces of code that just happen to be giving you what you want right now, that will fail with different data
      3. You'll probably learn bogus rules help you "solve" your problem sometimes, but don't work reliably

      If you combine trial and error with coming up with a hypothesis and testing it, you'll come up to speed faster. When you see an error message that you don't understand, try to figure out from context what sorts of things it may mean, and then make changes to test each of your hypotheses. If you come up with no guesses, it simply means that there are some rules that you're not even aware of yet. Reading about the operators, statements and functions in the immediate vicinity of the error can often clue you in to the rule(s) that you're missing.

      After you learn enough of the rules, debugging then becomes more of a deductive process--much easier and less frustrating than trial and error. You'll see an error message and immediately you'll think of a couple things to check on. If an unexpected value comes out of your code, you'll know where to look, and often what to look for.

      When you start out, always use strict and warnings--this way, you'll maximize the messages from perl that will give you so you can be more aware of some of the rules. But don't be afraid to turn them off (locally) when they're telling you about things that you intend to do.

      Finally, while you code, keep track (in the back of your mind) of the types of errors you make. I find that people often have patterns to the types of errors they make. If you know which errors you most frequently make, then you'll have a few things to quickly look for when you have a problem. (Example, some people may forget to initialize their variables, others may frequently misspell variable names, etc.)

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.