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.
In reply to Re: FILE READ and WRITE
by jonadab
in thread FILE READ and WRITE
by mbayer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |