in reply to Re^3: reading files to different output files.
in thread reading files to different output files.
yes, I tried it this way:
#! /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";
this script produces three output files, each contains the input filename that the user writes into the command line. Do I have to somehow open the input files in the script?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: reading files to different output files.
by marinersk (Priest) on May 28, 2017 at 14:05 UTC | |
by ic23oluk (Sexton) on May 28, 2017 at 15:11 UTC | |
by shmem (Chancellor) on May 28, 2017 at 16:16 UTC | |
by marinersk (Priest) on May 28, 2017 at 21:53 UTC |