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 | |
by ic23oluk (Sexton) on May 28, 2017 at 14:08 UTC | |
by marinersk (Priest) on May 28, 2017 at 14:19 UTC |