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

I am trying to create a form that will send a formatted e-mail based on info read in from a source file.
The code I have written as a test looks like this:
#!/path/to/perl -w open LIST,"/path/to/file/sorted" or die "/path/to/file/sorted: $!"; open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Died: $!"; format SENDMAIL = From: Me < Me\@example.com > To: You < You\@example.com > Subj: Status of test Thank you, Me UNIX System Administrator rebel and asic domains . write SENDMAIL ;
It gives the following error...
#./test.pl
syntax error at ./test.pl line 6, near "To:"
Execution of ./test.pl aborted due to compilation errors.

What is the dummy (me) doing wrong.
John
PS - I am very new at perl.

Replies are listed 'Best First'.
Re: format + mail
by blakem (Monsignor) on Sep 06, 2001 at 21:55 UTC
    formats aren't really used that often anymore. I'd suggest something like:
    #!/path/to/perl -w open LIST,"/path/to/file/sorted" or die "/path/to/file/sorted: $!"; open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Died: $!"; print SENDMAIL <<"EOF"; From: Me < Me\@example.com > To: You < You\@example.com > Subj: Status of test Thank you, Me UNIX System Administrator rebel and asic domains . EOF

    -Blake

Re: format + mail
by runrig (Abbot) on Sep 06, 2001 at 22:29 UTC
    Read perldoc perlform on how "@" characters are handled. To get a literal "@" on a line, you have to do:
    From: Me < Me@example.com > "@"
    This is because "@" is taken to be an argument substitution whether or not it is backslashed. I also wonder why you're using formats when your not substituting anything (I assume your example just doesn't reflect that part yet).

    blakem is right though, a here-doc might be more appropriate for this, depending on the actual body of your email, of course.