in reply to Re^3: How to create an output file for each input file
in thread How to create an output file for each input file

Hello, thank you!

yes, the files end in .TAB and I can define the values for $inbox and $outbox.

I think where I was getting confused was on the $verifile. Can you suggest what the separators are? Is this what causes a new file to be created each time it loops through?

Many thanks!
  • Comment on Re^4: How to create an output file for each input file

Replies are listed 'Best First'.
Re^5: How to create an output file for each input file
by apl (Monsignor) on Apr 02, 2008 at 23:01 UTC
    Rather than

    $verifile = $outbox.$yr.$mn.$day.$hr.$min.$sec."_FIXED.TAB";
    use something like
    $verifile = $outbox."_".$yr.$mn.$day."_".$hr.$min.$sec."_FIXED.TAB";

    (Keep it mind you have to populate the date and time fields.)

    You create the file by opening it. You should look at this tutorial on Open to decide exactly what you want to do.

      Thanks for the document. When I run my code (with variables defined) I am able to open a new file, but instead of it closing and then a second file being created, the dumby data is appended to the original single file. Is that because I'm using

      open(OUTPUT_FILE, ">>$verifile")||die "Can't open file: $!";

      close OUTPUT_FILE;
        '>>' says "append to an existing file". I believe a single '>' says 'create if necessary, over-write if it already exists'.

        When you do the print, do you print OUTPUT_FILE?

        If you post your current code, I (or someone else; it's bedtime for me) could better comment.

Re^5: How to create an output file for each input file
by steph_bow (Pilgrim) on Apr 03, 2008 at 10:41 UTC

    Hope it helps !

    ## loop through the TAB files### foreach $file (@files) { chomp; # just add $file so for each $file , there is a $verifile created $verifile = $file.$outbox.$yr.$mn.$day.$hr.$min.$sec."_FIXED.TAB"; open(OUTPUT_FILE, ">>$verifile")||die "Can't open file: $!"; #string manipulation will go here close OUTPUT_FILE; }# end for each file
      Thanks, steph_bow! For some reason I didn't see your post until after I posted the solution you had already come up with. Yes, because I didn't add the $file variable to my output file, the second unique file was never created. Now it does! I posted my final code in another reply... I think because I'm anonymous or something I don't get to see the whole thread or something? Means I should register, eh? Thanks, everyone, you've been very helpful!

        I think you mus modify "chosen depth" but I do not know how to do this. See ya !