in reply to Batch processing of files

open(TMP,">$tmp"); clobbers the previous contents. Move it out of the loop if your goal is to accumulate the results of each file.

Replies are listed 'Best First'.
Re^2: Batch processing of files
by kennethk (Abbot) on Feb 11, 2010 at 17:51 UTC
    Or you can leave it where it is now, and open the file for appending instead of clobbering the file:

    open(TMP,">>$tmp") or die "TMP open failed: $!";

    See perlopentut for more information.

    Update: Further reflection on what is posted would seem to imply this thread is not immediately pertinent to the OP.

      If you wanted to append to an exiting file, I'd still move the open outside of the loop. Why would you want to open the file repeatedly here?

      Anyway, both of our solution are wrong. It shouldn't be moved outside of the loop. I missed the rename originally.

        For the given code, I would not. I also would not open the same file twice in a loop instead of seek, fail to test my opens, or use external input in the statement open(FH,"$file");. But given the combination of "Here's part of the script" with the tendency for some posted scripts to not correspond to actual code, it seems that piece of information is potentially pertinent as is the tutorial.