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

please advise why cant I pass this $dat to the email message??
if (($old_word eq $curr_word) and ($old_word2 eq $curr_word2)) { $data = head('http://web/web.html'); print $data->{'_headers'}->{'last-modified'}; use Data::Dumper; my ($dat) = Dumper $content =~ (/'last-modified' => (.*$)/i); print "$dat\n"; #Print to screen here and it does work here. my %mail = ( To => 'you@email.com', From => 'me@email.com', Subject => "NO CHANGE HERE", Message => "$old_word and $old_word2 Web page las +t updated ->$dat\n", ); $mail{smtp} = 'smtp'; sendmail(%mail) or die "\nProblem! $Mail::Sendmail::error\n"; }

Email works fine and prints two variable contents ($old_word and $old_word2) in the email message but wont print the $dat variable in the email message but will print the $dat variable contents it to my screen.

Replies are listed 'Best First'.
Re: Passing variable to an email message.
by Anonymous Monk on May 09, 2002 at 14:36 UTC
    Just another correction to my attempt at this and it still doesnt work.
    if (($old_word eq $curr_word) and ($old_word2 eq $curr_word2)) { $data = head('http://web/web.html'); print $data->{'_headers'}->{'last-modified'}; use Data::Dumper; my ($dat) = Dumper $data =~ (/'last-modified' => (.*$)/i); print "$dat\n"; #Print to screen here and it does work here. my %mail = ( To => 'you@email.com', From => 'me@email.com', Subject => "NO CHANGE HERE", Message => "$old_word and $old_word2 Web page l +as updated ->$dat\n", ); $mail{smtp} = 'smtp'; sendmail(%mail) or die "\nProblem! $Mail::Sendmail::error\n" +; }
Re: Passing variable to an email message.
by kappa (Chaplain) on May 09, 2002 at 15:39 UTC
    Are you really sure that:
    print "$dat\n"; #Print to screen here and it does work here.
    ...actually prints anything? There's a non-negative probability that you just see the output of:
    print $data->{'_headers'}->{'last-modified'};
    ...and conclude that $dat gets some value while it doesn't!

    Update:
    You'd better treat what the head() function returns as a list, and take its third element to get what you need (and you need 'last-modified' header, AFAIU). Look:

    my $dat = (head('http://web/web.html'))[2]; print "last-modified header value: $dat\n";
Re: Passing variable to an email message.
by adamcrussell (Hermit) on May 09, 2002 at 15:40 UTC
    Some advice:
    -go to http://theoryx5.uwinnipeg.ca/CPAN/data/Mail-Sendmail/Sendmail.html and copy and paste the example code into your script. Modify the easy to follow example as needed.
    -use $Mail::Sendmail::error
      Please advise what to copy and paste in the Sendmail page listed.
        use Mail::Sendmail; %mail = ( To => 'you@there.com', From => 'me@here.com', Message => "This is a very short message" ); sendmail(%mail) or die $Mail::Sendmail::error; print "OK. Log says:\n", $Mail::Sendmail::log;
Re: Passing variable to an email message.
by Anonymous Monk on May 09, 2002 at 14:28 UTC
    I forgot to add that I do have the use LWP::Simple in my script. Please advise of any solution to my problem. Thanks