Win has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem with program structure
by whereiskurt (Friar) on Jun 27, 2007 at 17:40 UTC | |
Win: I think you're going to get verbally mauled for that post because your code is SO long and your "question" is clearly unclear. :-) Who could 'advise you' to start over, when they have NO idea what your problem/goal is? Remember... we're not in your cubicle right now. :) That being said.... let me just say three things about your style, to start off the 'constructive criticism': 1) Scalar MADNESS = Your program has WAY to many dollar sign sigils ($) everywhere. Consider looking up %hashes and using a 'data structure.' 2) Variable naming -- you're BEGGING for trouble using such long and mixed cased variable names (at least you have strict&warnings at the top!!) People/Monks can't care to read that many characters, so use $short $good $names. 3) Subroutine LENGTH -- You should be able to describe your goal/problem in a couple of paragraphs/sentences (ie. WTF you're trying to do. :-) ) Take that description and make a sub{} for each logically part. Please, re-edit your node in accordance with the Community's Standard, and I'm sure people will be lining up to help you. :-) Kurt | [reply] |
Re: Problem with program structure
by GrandFather (Saint) on Jun 27, 2007 at 23:37 UTC | |
Consider:
which is about half the length and includes the following changes:
The "bug" may be due to the exit (now in sub fail) btw. DWIM is Perl's answer to Gödel | [reply] [d/l] [select] |
| |
| |
Re: Problem with program structure
by blazar (Canon) on Jun 28, 2007 at 07:49 UTC | |
Please could people advise me on whether I need to start the program again. Ditto as above wrt what all the others wrote. Your program makes my eyes bleed, period. Thus if you ask me, then yes: your should rewrite it from scratch. Of course you should first learn how to do so rather than posting either the same very snippets over and over again or whole programs with vague rfcs attached to them. Consider: Read more... (2 kB)
Which I got out GrandFather's improved version of your program by further: This is not a complete rewrite because arrived at the point at which I stopped I had grown completely tired, the rest of your code scared me and hey, nobody is paying me for this... I hope you get the picture and can go on yourself. Consider that where I stopped I got 53 lines of reasonably terse code out of your original 99 ones. And I didn't want to change the logic too much, too. | [reply] [d/l] [select] |
| |
| |
Re: Problem with program structure
by toolic (Bishop) on Jun 27, 2007 at 17:04 UTC | |
| [reply] |
by marto (Cardinal) on Jun 27, 2007 at 20:50 UTC | |
"Does this program work the way you want it to work, and are you just wondering if there is a better way to recode it?" A good question, and a nice post :) A great many people have told Win to read How do I post a question effectively? over the years, since most of his posts are very poorly written due to the lack of effort he has consistently shown. And yes, these questions are for his job, which he gets paid for. Win has been a member of this forum for years, and spent a vast percentage of that time ignoring the advice that he asks for, and not learning from his mistakes. Take a look at his post history should you wish to get a handle on his level of effort. Martin | [reply] |
by BenHopkins (Sexton) on Jun 27, 2007 at 23:11 UTC | |
| [reply] |
| |
Re: Problem with program structure
by princepawn (Parson) on Jun 27, 2007 at 17:31 UTC | |
the "first", "second", "third" in the code above is probably better expressed using arrays where the numbers 0, 1, and 2 give you the first, second, or third element. overall, I think this program could benefit from an understanding of data structures, particular array and hash references. "Advanced Perl Programming" 2nd edition was great for this. 3rd edition by Cozens is a completely different animals. So, I recommend that you read perldsc and think hard about how it's contents could improve your program.
Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality | [reply] [d/l] |
Re: Problem with program structure
by princepawn (Parson) on Jun 27, 2007 at 17:41 UTC | |
Actually, ultimately, I suggest that you create a Cat object with certain attributes. Then you just need an array of these Cat objects. So, after mastering perldsc, read perltoot or by TheDamian's masterwork on the subject "Object-Oriented Perl"
Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality | [reply] [d/l] |
Re: Problem with program structure
by Anonymous Monk on Jun 28, 2007 at 03:23 UTC | |
| [reply] |