Re: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
by marto (Cardinal) on Dec 31, 2007 at 14:37 UTC
|
Nik,
Given that you have been posting here (and on devshed, often cross posting the same question) for many years you don't seem to have taken the repeated advice from the monks, and learned some basic Perl and general programming skills. There is no evidence here that you have made any effort to debug this problem for yourself. jettero has kindly given you a huge hint.
Many could see this continued behavior as being lazy, some could find it offensive that you continue to make no either little or no effort in simple debugging techniques, and even less in the way you describe/present your problem and expect people to spoon feed you a solution, while they (often) painfully have to extract further information relating to your current issue.
Perhaps, with it being this time of year, you could make a new years resolution to develop better learning/programming habits.
Martin | [reply] |
Re: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
by jettero (Monsignor) on Dec 31, 2007 at 14:23 UTC
|
die "error opening $ENV{'DOCUMENT_ROOT'}/data/text/$_: $!"
instead of an nondescript die $!, you would immediately see the problem I bet.
| [reply] [d/l] [select] |
|
| [reply] |
|
Isn't while (@files) a valid statement meaning iterate on every item of array @files?
It is a valid statement, but it does not mean what you think it means. It iterates as long as @files is true, i.e., forever (since you do not modify @files). Again, I implore you to go read perlsyn (and/or a good perl book) and learn something.
| [reply] [d/l] [select] |
|
|
|
|
|
Re: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
by runrig (Abbot) on Dec 31, 2007 at 17:21 UTC
|
while (@files) {
Read perlsyn on the difference between the various forms of compound statements and loop control. | [reply] [d/l] |
Re: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
by ysth (Canon) on Dec 31, 2007 at 21:38 UTC
|
You mean "for" where you have "while". Simple debugging could have found this problem for you. After verifying that @files is set correctly, there are two possibilities: $ENV{DOCUMENT_ROOT} is not what you think it is or $_ is not what you think it is. Either step through your code in the debugger or insert debugging print statements; you will quickly discover $ENV{DOCUMENT_ROOT} to be correct, but some wacky value for $_. At this point, you know that while() is not setting $_ as you expected; either you decide perl is way to buggy and move on to PHP, C#, or the like, or you review the fine manual and discover that while() loops until an expression is true, not loops over an array.
| [reply] |
|
foreach (@files) {
open FILE, "<$ENV{'DOCUMENT_ROOT'}/data/text/$_" or die "error open
+ing $ENV{'DOCUMENT_ROOT'}/data/text/$_: $!";
then i got this error error opening D:/www/data/text/D:/www/data/text/Ένα μήνυμα σε όλους τους άπιστους.txt: Invalid argument at D:\www\cgi-bin\init.pl line 70.
$ENV{DOCUMENT_ROOT} i correct and $- is correctly set to but why not open Ένα μήνυμα σε όλους τους άπιστους.txt which is a file that does exist on /data/text ? | [reply] [d/l] |
|
The answer is right there in the error message -- you just have to read it carefully. Here is just the filename string from the error message:
D:/www/data/text/D:/www/data/text/Ένα μήνυμα σε όλους τους άπιστους.txt
Can you see the problem now? You have the value of $_, which comes from a file glob, and that value is:
D:/www/data/text/Ένα μήνυμα σε όλους τους άπιστους.txt
Then, inside the loop, you append that value to this string:
$ENV{'DOCUMENT_ROOT'}/data/text/
and the result of that concatenation is that the disk and directory path appears twice in the string that is passed to "open()". Fix that, and it will probably work as intended. | [reply] |
|
|
|
|
|
|
foreach (@files) {
open FILE, "$_" or die "error opening $_: $!";
...
}
Here is a cool video at google explaining glob
http://www.youtube.com/v/j5vWBhq49ps&rel=1 | [reply] [d/l] |
|
I know there are complications with opening files with non-ASCII characters on windows, but don't know a lot about it. It's been discussed here before, though.
| [reply] |
Re: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
by graff (Chancellor) on Dec 31, 2007 at 17:27 UTC
|
Sorry, Nik, I have to agree with what marto said. Maybe it's the language barrier (English vs. Greek) that keeps getting in your way, or it's some sort of learning disability that you have. Maybe you are simply not cut out to be a programmer. But I find it really strange that your script contains this line:
while (@files) {
What are you thinking when you write stuff like this? Are you thinking? Try thinking: "what would that sort of while loop actually do?"
Good luck. | [reply] [d/l] |
|
It's possible that he wrote that thinking "for" but typing "while". And then read it over and over again looking for an error, each time not noticing that it was a while, not a for. I know that kind of thing happens to me not as infrequently as I would wish.
| [reply] |