Richard C 1 wrote: > > I am a total beginner to perl. I wrote the program below to open a program > file, read it line by line, and write each line to an output file after > first putting two string lines out there. It compiles without errors but the > output is a filename with zero length. What did I do wrong? Thank you! > > #!/usr/bin/perl -w > use strict; > > open (infile, "<<moo.cgi"); ^^ This should be: '<moo.cgi' << is used for here documents, a quoting style inherited from the shell (AFAIK) You should also test that open succeeded.
open INFILE, '< moo.cgi' or die "Cannot open 'moo.cgi' $!"; > open (outfile, ">>snert.cgi"); ^^ This append mode, if the file already contains data your new data will be appended at the end of the existing data. open OUTFILE, '>> snert.cgi' or die "Cannot open 'snert.cgi' $!"; > my @linesin = <infile>; > > foreach (@linesin) { You would normaly use a while loop in this situation. while ( <INFILE> ) { > print outfile "output line 1\n"; > print outfile "output line 2\n"; > print outfile "$_\n"; > > } > > close (infile); > close (outfile); Oh, and file handles are usually in all upper case. :-) Read the perlopentut document that comes with Perl. perldoc perlopentut John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]