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

I am using a perl script supplied by my server who is at a loss at why I get this error. The line in question is:

send_mail($email_400, <<EOF );

The other set of lines are:

if($email_400) { send_mail($email_400, <<EOF ); To: $email_400 From: webmaster\@$main_domain Subject: Missing file A request was received for the file $ENV{REDIRECT_URL}, which does not + exist. The referer was $ENV{HTTP_REFERER}. EOF }

Is this sufficient info? Tks

Replies are listed 'Best First'.
Re: uninitialized value in concatenation
by ikegami (Patriarch) on Nov 16, 2010 at 19:33 UTC

    You cut off a relevant part of the error message: "or string". You have a string literal (<<EOF .. EOF) which interpolates an undefined variable. $email_400, $main_domain, $ENV{REDIRECT_URL} or $ENV{HTTP_REFERER} evaluates to undef. A more recent version of Perl would actually identify which in the error message.

      Possibly relates to the opening lines of the script</>

      #!/usr/bin/perl -w use strict; my ($email_400, $email_500, $unfriendly_error, $redirect_to); my $main_domain=getpwuid($<); my @sendmail_path=(qw(/usr/sbin/sendmail -i -odb), "-fdcm\@nineone.org +"); ## Uncomment the below two lines to get emailed regarding the respecti +ve ## errors. $email_400="dcm\@$main_domain"; $email_500="dcm\@$main_domain";

      should I give the whole script - 110 lines?

        should I give the whole script - 110 lines?

        Why? The warning has already been explained. (I was going to say your question has already been answered, but you have yet to actually ask a question.)

        I presume you want to know which variable isn't defined and why, but that's simple debugging. You can use defined to determine which variable isn't defined. To find out why it isn't defined, find out where the variable is getting set (if it's getting set at all) and find out when the initialiser might be undefined.

Re: uninitialized value in concatenation
by kcott (Archbishop) on Nov 16, 2010 at 21:02 UTC

    Before building the email message, check all variables and perform appropriate actions if they aren't set or don't have suitable values. Those actions might be to call an error handling routine, output a warning message, supply a default value and so on.

    You might also consider building the components of the message separately. For instance:

    if ($email_400) { my $problem_description = $ENV{REDIRECT_URL} ? "A request was received for the file $ENV{REDIRECT_URL}, whi +ch does not exist." : "A file request was received but no filename was supplied."; send_mail(... ... $problem_description ... EOF

    -- Ken

      Thanks for those two responses. I shall have to carry on tomorrow pm Gilbert
Re: uninitialized value in concatenation
by aquarium (Curate) on Nov 16, 2010 at 23:31 UTC
    you can't use a here document like that send_mail($email_400, <<EOF ); because there's a right bracket and semicolon introduced as part of the here document or the start here document marker. either result is undesirable. A here document start marker needs a semicolon directly after the here document name (EOF in this case) afaik. one possible way is
    if($email_400) { my $email_content = <<EOF; To: $email_400 .. .. EOF send_mail($email_400,$email_content); }
    the hardest line to type correctly is: stty erase ^H
      A here document start marker needs a semicolon directly after the here document name (EOF in this case) afaik.

      No, other stuff can follow the marker if required. I often use this to inline data in a HEREDOC and open it as if it was a file.

      knoppix@Microknoppix:~$ perl -Mstrict -we ' > open my $fh, q{<}, \ <<EOD or die qq{open: < HEREDOC: $!\n}; > line 1 > line 2 > line 3 > EOD > > while ( <$fh> ) > { > $_ = ucfirst; > print; > } > > close $fh or die $!;' Line 1 Line 2 Line 3 knoppix@Microknoppix:~$

      I hope this is of interest.

      Cheers,

      JohnGG

        thanks JohnGG, that's interesting...i must be getting old now if i'm forgetting stuff from the manual...where's a lake so i can do fishing instead?
        r u really running on a knoppix?..on a mobile device?
        the hardest line to type correctly is: stty erase ^H