December 20th, 2012, 10:10 AM
At wit's end with Perl Script
I'll give a very brief background. I am in the mortgage business, and have prospect data loaded into Excel spreadsheets. Online I found a way (VBA) to break up the dozens of worksheets into individual .csv files. So far so good.
I am using a Perl script to loop through the directory and read each of these .csv files and pull out specific pieces of data. Each .csv file is approximately 40 lines long.
In doing so, I see that most of the files are being read, but some, for whatever reason are giving an error message that the file is unable to be read, and it is on on line 70 of the data file. It also says that there is a read error in the script itself.
Thinking that this might be something in the text in the .csv, I have removed all of the text, and am still getting similar messages. Is there any reason that Perl could open some files and not others?
Is something overflowing in the program to cause this? Thinking it may be a permissions issue somehwere, but it is inconsistent,
Any help would be greatly appreciated.
December 20th, 2012, 10:50 AM
Seems like the obvious thing would be to open one of the "unreadable" files in a text editor and look at line 70. Must be something different about it, unusual characters or line endings.
If perl is reaching line 70, then the file was open and is being read.
December 20th, 2012, 11:06 AM
There is no line 70 in any of the .csv files, as it only goes to 40 or so. In reviewing the code again in my head (am away from the computer for awhile), I need to ask really dumb question, and I should know better. Should I be closing each .csv after reading them, as I believe I wasn't?
This alone could undoubtedly cause issues.
I will go back and do this and report back if the issue still persists.
Thanks for your time.
December 20th, 2012, 11:29 AM
Explicitly closing filehandles is a good practice to adhere to, but may not be required.
Can you post your code, the complete error message and the csv file? With that info, we should be able to locate the source of the problem.
December 20th, 2012, 03:31 PM
Entered the Close statement after I was done with the file, and still got the same result. Something is preventing it from opening, regardless if there is text in it.
How would I go about posting this? This file is hundreds of lines long. Can I email it to someone?
December 20th, 2012, 04:17 PM
You can post/upload the files as attachments.
Look at the "Additional Options" section just below the reply window.
December 20th, 2012, 05:42 PM
Wasn't able to get back to this after I posted this morning, but almost as soon as I had, I wished I had asked the more important questions:
How are you reading the CSV file? Are you using a perl CSV module? If so, which one. Are you reading line by line or trying to pull the whole file into memory?
You'll need to show a bit more of your code if the problem persists.
December 21st, 2012, 09:24 AM
Issue can be marked as resolved. The original question regarding the closing of the fille was just part of the issue. After closing it, still got messages that I was unable to open the file.
It boiled down to a permissions issue. Before opening the files I ran a CHMOD command and they all opened fine. For whatever reason the .CSVs were generated in VBA with different permission levels. Either way, they are all accessible now.
Thank you so much to all that have helped me get to this point.