sudip_dg77 has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Please help..
by Corion (Patriarch) on Apr 15, 2008 at 09:32 UTC | |
One point why you seem to be not moving forward is that you don't show any effort on your part. For example, the first result set has the following fault description:
A simple approach would be to identify the line of code that outputs the headers and then to output a newline there. Maybe you can explain to us where your difficulty is with locating that line and outputting a newline there. The same goes for the third fault:
Maybe you can tell us which steps are necessary here to fix that. I recommend looking through the documentation of the print function for a solution. At least these two "faults" are trivial to fix, but you have not shown any effort to identify where the errors occur or to fix them. As part of showing effort, you should reduce your script to the bare minimum to produce the error. As the error is in the output, you should remove all input, all database queries etc. from your program and replace it with static data until you end up with the minimal program that still produces your faulty output. Most likely, then the error will be obvious. BTW, the "fault comments" sound to me as if they are not by you but by somebody else reviewing your work. If that somebody is your teacher, maybe you should review your course materials to look at what you should have learned in your course. | [reply] [d/l] [select] |
|
Re: Please help..
by marto (Cardinal) on Apr 15, 2008 at 09:51 UTC | |
I have a question, what have you done to help yourself? Your previous thread had answers giving you lots of advice, why post the same question again and not continue the thread? Have you looked at the Tutorials section of this site? It has various tutorials covering topics such as leaerning Perl (hint) and debugging code. You should read How do I post a question effectively? and the PerlMonks FAQ, since 'Pleae help..' is hardly a descriptive title. Martin | [reply] |
|
Re: Please help..
by stiller (Friar) on Apr 15, 2008 at 10:11 UTC | |
Still, I will give you a pointer:
You might want to take a look at the docs: http://search.cpan.org/~timb/DBI/DBI.pm#fetchall_arrayref keep up the spirit! | [reply] [d/l] |
|
Re: Please help..
by andreas1234567 (Vicar) on Apr 15, 2008 at 10:56 UTC | |
Does perltraining.org have anything in your area?
-- Andreas | [reply] |
|
Re: Please help..
by talexb (Chancellor) on Apr 15, 2008 at 13:52 UTC | |
Instead of trying to get this piece of code to run -- which I suspect is something that you've taken over from a departed developer or consultant -- see if you can write something from scratch that does just the first result set. Get that working properly, learn from it, and then go on to the next result set. | [reply] |
|
Re: Please help..
by starbolin (Hermit) on Apr 15, 2008 at 15:58 UTC | |
I read the OP's previous post and there exists evidence of improvement; therefor, I suggest you guys are being overly harsh. The poster included his output and the desired output; which is more that most posters give us. Not everyone can be an instant Perl God. Your script sudib_dg77, as posted, contains a simple but insidious error in that early on there is a statement lacking a terminating semicolon. This will cause the rest of the script to not parse properly. Further, it will cause small changes in the script to result in differing behaviours. A situation similar to the troubles you have been encountering. I don't know if this was part of code that you edited out for this post, as it appears to be, or if this is reflected in you production code. If the latter, posting incomplete code is not the same as posting simplified code and is less than helpful. Your code lacks proper formating in that the indentations seem to be added at random. While the perl compiler doesn't care, those of us reading the code are confused by random indentations. Please only indent statements that are contained inside brackets or are continuation of partial lines. I had to run your code through perltidy in order to read it without straining my poor Pooh-brain. Consequentially, check out perltidy. It's an excellent tool for the new perler.
"If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that." Excellent advice! It appears that you are doing exactly that, ie. fetching into a scalar $row. This will cause loss of data as you describe. Good luck. And I'll apologize for the other's harshness. I hope it doesn't unduly discourage you. <update> Update: strikeout misquote.</update> s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo} | [reply] |
by starbolin (Hermit) on Apr 15, 2008 at 17:34 UTC | |
OOPs! I misquoted fetchall the quote was from fetchrow. Bad, Bad starbolin. But, now I notice that you do not use the value returned from fetchall. How come? I would expect to see something like print @{$row} where $row is dereferenced back to an array or foreach @{$row} { do-something-with-$_ } to loop over the data in the array referenced by $row. Do you understand references? Do these statements make sense? If not, perhaps a read of perlreftut is in order.
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo} | [reply] [d/l] [select] |