Update with code: As the docs for open point out, this is NOT the preferred way to do it, but does this perhaps do what you wanted (preserve the prior content of main_log.txt, and append the content of sub_log.txt)?
# 795500 # $| = 1; # autoflush my $main_log = 'main_log.txt'; my $sub_log = 'sub_log.txt'; open LOGFILE, '<', $main_log or die "Cannot open $main_log for read, $!"; my $prior_content; while (<LOGFILE>) { $prior_content = $prior_content . $_; } close( LOGFILE ); open LOGFILE, '>', $main_log or die "Cannot open $main_log for write, $!"; print LOGFILE $prior_content; print LOGFILE "\n---\n"; print LOGFILE "\n\tStart: Coming from the script.\n"; open( SUBLOG, '<', $sub_log ) or die( "Error: Cannot open sub_log" ); print LOGFILE $_ while( <SUBLOG> ); close( SUBLOG ); print LOGFILE "\n\tEnd of sub_log as read by script.\n"; print LOGFILE "\tEnd: Coming from the script.\n"; close( LOGFILE );
If it's not what you intended, you may wish to deal with the problems almut pointed out... AND clarify your question (because your code doesn't do so for me).
In reply to Re: How to Write Information to an Opened File
by ww
in thread How to Write Information to an Opened File
by bichonfrise74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |