"Uri Guttman" <u...@stemsystems.com> writes:

>>>>>> "HP" == Harry Putnam <rea...@newsguy.com> writes:
>
>   HP>     open(SENDMAIL,"|$sendmail $recip")  or die "Can't open <$sendmail>: 
> $!";
>   HP>     while (<SENDMAIL>) { 
>
> what is that line supposed to do? it reads from the SENDMAIL handle
> which is opened for WRITING. why do you think you need that or even to
> loop over that handle? just print to it.

I see now I could just write to the handle in one blob ($emailmsg)

Just that change; from a while loop to simple print to handle, makes it
do what I was after.

Thanks...

> and yes, this is garbage code. there are many easy to use mail modules
> that will use sendmail or any available mail service for you.

With such a simple call to sendmail, is it still better to involve
extra modules as you suggest above.
Are these modules you mention easier to use than:
  
  open(SENDMAIL,"|$sendmail  $recip") or die "Can't open <$sendmail>: $!";
  print SENDMAIL $blob;
  close(SENDMAIL);

>   HP>       print SENDMAIL "$emailmsg\n";
>   HP>       print "$emailmsg\n";
>   HP>     }
>   HP>     close(SENDMAIL);

> when you open a piped process, check the close as that is where you will
> actually find any errors from the open. since open | does a fork/exec,
> it can't tell you if the exec fails until you close the handle.

Not sure what you are suggesting to do there.  I mean other than ditch
the code in favor of a module.  Do you mean to put the `die' after the
CLOSE?

Even without that though, wouldn't any errors at CLOSE still print to
stderr?

>   HP>   } else {
>
> why the else? $MAIL is 'TRUE' so this will never execute.
>
>   HP>     for (@body) {
>   HP>       print "$_\n";
>   HP>     }

I did mention in the first few lines of OP that I had snipped the code
from a larger script I'm working on, to make it work standalone for
testing... in the larger script there is a reason for the `else'.
Mail being true really depends on a getopts option having been
selected. else....  just print.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to