in reply to Re: I need to append to text file
in thread I need to append to text file

your code is certainly correct (even if it doesn´t use strict;), but aatlamaz states that he couldn't handle newline problem. That leads me to the assumption, that at least one of the files has no newline at its last line. Thus it must be added.
So i changed above code to handle that (while also adding argument handling and support for more than two files):
use strict; my $outfile = pop @ARGV or die "No outfile!\n"; my @infiles = @ARGV or die "No infile(s)!\n"; open OUTFILE, ">$outfile" or die "Cannot open $outfile!\n"; for ( @infiles ) { open (INFILE, $_) or die "Can't open $_!\n"; while ( <INFILE> ) { chomp; print OUTFILE "$_\n"; } close INFILE; } close OUTFILE;


The script can be called like this:
shell: perl script.pl file1 file2 fileN outfile

holli, regexed monk