harry34 has asked for the wisdom of the Perl Monks concerning the following question:

I have a while loop which iterates 27 times and adds new
data (six columns of data in total) to the end of the
existing text file.

open (TEXT, ">>cell_.txt") or die "Can't create cell_.txt: $!\n"; printf TEXT "%14.11f %14.11f %14.11f %14.11f %14.11f %14.11f\n",$ +a, $b, $c, $alpha_deg, $beta_deg, $gamma_deg; close TEXT;

how would generate a new text file with each iteration ?
So I have 27 files with six values in each ?

thanks harry

Replies are listed 'Best First'.
Re: filehandle
by amphiplex (Monk) on Jul 05, 2002 at 10:38 UTC
    Yuo could do something like this:
    for (1..27) { open TEXT, ">cell_$_.txt" or die "Can't create cell_$_.txt: $!\n"; printf TEXT "%14.11f %14.11f %14.11f %14.11f %14.11f %14.11f\n" +,$a, $b, $c, $alpha_deg, $beta_deg, $gamma_deg; close TEXT; }

    Of course you will have to set the variables inside the loop, but you propably are doing this already.

    ---- kurt
Re: Creating a new file each iteration
by cybear (Monk) on Jul 05, 2002 at 19:50 UTC
    If the above code is inside your loop, changing open (TEXT, ">>cell_.txt")
    to open (TEXT, ">cell_$somevariable.txt") should do it.