Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want the output of bas.txt to show up in the message portion of my email. Please advise what I am doing wrong. I have tried it many many ways but no luck yet???? My email makes it to me but only prints out $_.
use LWP::Simple; use Mail::Mailer; open(RES,"type bas.txt |"); while(<RES>) { print $_; } use Mail::Sendmail; my %mail = ( To => 'toemailhere', From => 'fromemailhere', Subject => "Output", Message => '$_', ); $mail{smtp} = '111.222.222.333'; sendmail(%mail) || die "\nProblem! $Mail::Sendmail::error\n"; close(RES);

Replies are listed 'Best First'.
Re: Output data into an email message.
by DamnDirtyApe (Curate) on Sep 03, 2002 at 17:13 UTC

    Rather than messing around with pipes, why not just capture the file to a scalar:

    open RES, 'bas.txt'; my $msg; do { local $/; $msg = <RES> }; close RES;

    ...then just send that.

    my %mail = ( To => 'toemailhere', From => 'fromemailhere', Subject => "Output", Message => $msg );

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
      Thanks!!! Just not sure about what your doing with: my $msg; do { local $/; $msg = <RES> }; I am not familiar with local $/; part?? If possible can you explain? I assume the 'do' is a do while statement??

        local $/ means "don't split lines"

        do { } means "only here"

        It combines to: "read whole file as if it were a single line"

Re: Output data into an email message.
by zigdon (Deacon) on Sep 03, 2002 at 17:00 UTC
    Just at first glance, you have '$_' when you mean "$_" - note the double quotes instead of the single ones. Single quotes mean "as is", while double quotes man "interpolate variables". Another thing I see, which may or may not be a problem, is that by the time you get to the sendmail() command, you only have the last line of bas.txt. Perhaps you want to replace the while loop with something like:
    $txt = <RES>; print $txt;
    -- Dan
Re: Output data into an email message.
by insensate (Hermit) on Sep 03, 2002 at 16:59 UTC
    You've supressed variable interpolation by using single quotes...put $_ in double quotes.
Re: Output data into an email message.
by fglock (Vicar) on Sep 03, 2002 at 17:17 UTC
    open(RES,"type bas.txt |"); while(<RES>) { print $_; }

    could be written as:

    open(RES,"bas.txt"); @text = <RES>; $all_text = join(@text); print $all_text; ... Message = $all_text;

    update: I took too long to type... See the message before this :)