Hi Monks:
In code block below, the saved fh's are not restored and a print command executed later in a different module prints to my log. If I close the handle it produces a print to closed handle error.
The email is completed and sent and the logging shows continued posting to the $fh/log after returning to the caller and the callers caller.
How do I restore the handles and close $fh?
Looks to me like some examples I found in "The Monastery"
Thanks
sub SendMemberMail { my ($subject,$from,$to,$port,$cc,$bcc,$heading,$body,$closing,$signi +ture,$auth) = @_; # Open log for recording during execution of SendMail my $sendMail_logfile = '/home/abcus/public_html/httpsdocs/cgi-bin/li +b/perl/Mail/mail.log'; open(my $fh, "+<", "$sendMail_logfile") or die "Opening: $!"; my $previous_STDOUT_fh = select(STDOUT); my $previous_STDERR_fh = select(STDERR); #Redirect STDERR & STDOUT to $fh for this sub *STDOUT = $fh; *STDERR = $fh; my $message = ($heading . "\n" . "\n" . $body . "\n" . "\n" . $closing . "\n" . "\n" . $signiture . "\n" ); if ($auth == 1) { $auth = {user=>'webmaster@abc.us', password=>'wm@xxxx', method=>'P +LAIN LOGIN', REQUIRED=>1} } elsif ($auth == 0) { $auth = ""; } my %mail = ( To => $to, From => $from, Cc => $cc, Bcc => $bcc, Auth => $auth, Port => $port, Subject => $subject, Message => $message, debug => 18 ); SendMail(%mail) or die $Mail::sendMail::error; $log .= "Sending eMail Succeded\n"; #Print the data from the $log. print $fh $log; #restore the standard handles select($previous_STDOUT_fh); select($previous_STDERR_fh); close($fh); return 1; }
In reply to STDERR Restore after redirect by tultalk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |