Carrie Lyn Brammer wrote: > > I've looked throgh the recent archives. A lot of what > is being discussed seems too 'advanced' for me. I guess > i'm a REAL baby newbie. > > Can someone please look at the following project, and > tell me why it is not writing the contents of the > readfile.txt to the writefile.txt? > > It's tough to learn from a book, when there is no one to > help you, and no examples of the project anywhere. I > wish I could get a free personal tutor. Anyone interested? > heh. > > Here is what i've got so far: > > --------------------- > > # Description:A program that can save the contents of a given file and create a > # new file in the same directory that contains a copy of the original files >information > # Revision History: > # 1.0/July 18th 2002: original version > #-----------------------------------------------------------------
You should let Perl help you find mistakes with warnings and strictures. use warnings; use strict; > # open files for reading(readfile.txt) and writing(writefile.txt) > open (READFILE, "readfile.txt") || die "could not open readfile.txt \n"; > open (WRITEFILE, ">writefile.txt") || die "could not open writefile.txt \n"; Putting the variable $! in your error messages will tell you why the error occured. > # define contents of readfile.txt to array > @contents = <READFILE>; > > # print contents to the writefile > print (@contents); You are printing to standard output (STDOUT is the default) instead of the file you want to print to. print WRITEFILE @contents; > # close readfile and writefile > close (READFILE); > close (WRITEFILE); > > # open writefile.txt to read contents > open (NEWWRITEFILE, "writefile.txt") || die "could not open writefile.txt\n"; > > # assign contents of writefile.txt to an array > @newcontents = <NEWWRITEFILE>; > > # print the contents of writefile.txt > print "\n The contents of writefile.txt is $newcontents \n"; > > # close writefile.txt > close (NEWWRITEFILE); Instead of reading the contents of one file into an array and printing that array to another file you could do it like this: while ( <READFILE> ) { print WRITEFILE; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]