in reply to FILE READ and WRITE
In cases like this, you can get more detailed error messages by printing $! if certain builtin functions (like open or close) return false. Also, you probably want two different filehandles, since you're wanting to use both at the same time.
$output_file = "ConsumerMV.sh"; $input_file = "mikels.out"; $quit_code = "quit\n"; open(INFILE, $input_file) or die "Cannot read from input file: $!"; open(OUTFILE, ">$output_file") or die "Cannot write to output file: $! +"; while(<INFILE>){ chomp; print "Saw $_ in data.txt\n"; print FILEHANDLE $_ or warn "Can't print: $!"; } close INFILE or die "Can't close INFILE: $!\n"; close OUTFILE or die "Can't close OUTFILE: $!\n";
I believe I left (at least) one error in the code, but because of the added sanity checks, you'll now probably find it right away, as soon as you run the thing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: FILE READ and WRITE
by ikegami (Patriarch) on Nov 22, 2005 at 23:05 UTC | |
|
Re^2: FILE READ and WRITE
by mbayer (Novice) on Nov 22, 2005 at 20:42 UTC |