in reply to How to create an output file for each input file

What exactly do you mean when you say you want to create a new output file for each input file? Will the output file contain selected lines from the input file? How will the output file be named, viz a viz the input file? Which search functions did you look at?

And most importantly, what have you written to try to implement a solution to your question?

  • Comment on Re: How to create an output file for each input file

Replies are listed 'Best First'.
Re^2: How to create an output file for each input file
by Anonymous Monk on Apr 02, 2008 at 20:26 UTC
    I'm trying read each file in a directory, change some of the text, then write it to a new file in another directory.

    Here's what I've written:

    #get the names of all .tab files in inbox directory opendir(DIR,$inbox); @files = grep(/\.TAB$/,readdir(DIR)); closedir(DIR); ## loop through the TAB files### foreach $file (@files) { chomp; $verifile = $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

    Edit: g0n - code tags

      A few more questions:
      • Do the existing files end .TAB or .tab?
      • You will need to define $inbox and $outbox.
      • You will need to add something to the value of $verifile to reflect $file. (That is, /old/WARRANT.TAB should result in /new/WARRANT_080402_164500_FIXED.TAB which requires some separators as well)
        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!