SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Need to kill while loop on any error

    I have been running I/O scripts for years, and never ran across this little bug...

    When parsing in an entire file using a while loop, I fill different variables based on different REGEXPs. The problem arises when one of my REGEXPs is not perfect, and fills a variable with nothing... causing an invalid concatenation error, but not just for that line... for EVERY line...

    The problem is not so mush that I need to fix the errors, but I am parsing a 485,679 line file, generating ~2000 errors per second in my Apache error_log file... which incidentally I do not have permission to modify/delete... at that rate, debugging my REGEXPs fills up MBs fast.

    hehehe... last week, before I found out about this, I blew away a 900 MB chunk of error_log...

    SO..... is there some way I can just kill the while loop on ANY error, so that I don't write more than one error to the error_log???

  2. #2
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can always use "no warnings;" in that section of the code to suppress warning messages. Or check the return value of the regexp's and use "next" to go to he next iteration of the while loop if the return value is undefined

    Code:
    while(<INPUT>)
    if (/(foo)/) {
       $variable = $1;
    }
    else {
       next;
    }
    or something similar.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •