#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    At wit's end with Perl Script


    Good Morning,

    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.


    Thanks
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,252
    Rep Power
    1810
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Hi Keath,

    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    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?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    You can post/upload the files as attachments.

    Look at the "Additional Options" section just below the reply window.
  12. #7
  13. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,252
    Rep Power
    1810
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo