in reply to Process large text data in array

My major concern now is what will happen when user interrupted the process in the while..loop when file still open?

open (DATF, "<$file_name"); while( <DATF> ) { #-- do whatever here #-- user may interrupt before finishing the while...loop } close(DATF);

Should I be worry of this? Currently I'm only using this while...loop method for input only (read). As for writing data, likely data gonna corrupt.

Any suggestions on this? Thanks.

Replies are listed 'Best First'.
Re^2: Process large text data in array
by BrowserUk (Patriarch) on Mar 11, 2015 at 13:56 UTC
    My major concern now is what will happen when user interrupted the process in the while..loop when file still open?

    The same thing as would happen if he interrupted the program while you were filling the array in your OP code.

    That is: the file will be closed and the program will exit without producing any output. As you are only reading the file, no data will be harmed.

    Of more concern is what happens if you are producing output from within the while loop. Then, if the user interupts, the output file can contain only partial data.

    To address the latter concern -- and prevent any worries about the former -- install an interrupt handler near the top of your program (or in a BEGIN block):

    $SIG{ INT } = sub{}; ... while( ... ) { ... }

    That will prevent the user interrupting with ^C. You can do a similar thing for most</> other signals that the user might use to interrupt.

    Serach for "%SIG" in perlvar.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Oh wow, this is something New for me to look into.

      What if the interrupt is line disconnected/closing browser/stop page loading? My program are mainly run thru www web browser, there is no command line execution in concern here. Does the interrupt handler you suggested able to capture this or they are all same?

      In my own theory, if possible to capture such interrupt with custom INT handle function, then I should be able to do some cleanup in the function. Eg.

      sub INT_handler { # check for any unfinished jobs # close all files exit(0); } $SIG{'INT'} = 'INT_handler';

      The code above are my own untested modification theory from google search.

        My program are mainly run thru www web browser, there is no command line execution in concern here. Does the interrupt handler you suggested able to capture this or they are all same?

        Sorry, but I'm not qualified to answer that question. I suggest you post a new SoPW along the lines of:"What sources of interrupts can affect my perl/CGI script; and what can I do about them?".


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked