in reply to Re: reading files to different output files.
in thread reading files to different output files.

yes, but it didn't work. here's my entire script:

#! /usr/bin/perl use strict; use warnings; use IO::File; my @fh; my @file_names = ("output1.txt", "output2.txt", "output3.txt"); while ( <> ){ for (my $i=0; $i<=$#file_names; $i++){ $fh[$i]= IO::File->new( ">$file_names[$i]" ) || die "Cannot op +en $file_names[$i]: $!.\n"; print {$fh[$i]} "$_"; } } print "done.\n";

It produced three output files, each containing the command that i entered in the command line. What's missing?

Replies are listed 'Best First'.
Re^3: reading files to different output files.
by Anonymous Monk on May 28, 2017 at 14:03 UTC

    Why use <> if you allready have the array list?

      I am in very early stages and not even familiar with the basics, maybe thats why. could someone please improve my script? would be very pleased.

        I think you'll find the mission of the Monastery isn't to fix your scripts quite as much as to help you in your personal path toward being able to fix your own scripts.

        Above, I fed you a sample of how to read a file. Surely you can use that as the basis for modifying your script to read files before trying to write other files, yes?