in reply to Add a Line to a Text File
use strict; use warnings; my $infile = $ARGV[0] or die "$0 Usage:\n\t$0 <input file>\n\n"; open(my $fd , '<' , $infile) or die "$0 Error: Couldn't open $infile f +or reading: $!\n"; my $outfile = 'processedData.txt'; open(my $fh, '>', $outfile) or die "Could not open file '$outfile' $!" +; my $previous; print $fh "data\n"; while (<$fd>) { $previous = $_; print $fh $previous; } chomp($previous); close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Add a Line to a Text File
by Athanasius (Archbishop) on Aug 24, 2013 at 04:04 UTC |