Re: [OT] Re: sendMail in cgi program

2000-06-13 Thread Ian Kallen


Well, you _can _ do this
$var="END";
   This is my variable's
   multiline text,
   complete tith tabs\t\t and extra newline\n\n, etc
END

four spaces in the opening and closing quote.  I usually use qq{ }
depending on how much I care about whitespace formatting.  If I was
writing Perl code to generate Python code, I'd be in trouble (in more
than one way).


Paul wrote:
 As someone mentioned on the board (ever so briefly), here-documents
 like this one require that your "sentinel" string have no leading
 whitespace.
 
 e.i., you may say
$var=END;
   This is my variable's
   multiline text,
   complete tith tabs\t\t and extra newline\n\n, etc
 END
 
 but you *can't* say
$var=END;
   blah
END
 
 because here, END has space in front of it.
 In several shells you can put tabs in front of it if you say
print-END; # the dash says "let me use a leading tab"
blah
 tab hereEND

--
Salon Internet  http://www.salon.com/
  Manager, Software and Systems "Livin' La Vida Unix!"
Ian Kallen [EMAIL PROTECTED] / AIM: iankallen / Fax: (415) 354-3326



RE: sendMail in cgi program

2000-06-12 Thread Jerrad Pierce

This is not for CGI however, the problem is simple.
EOF must be at the beginning of the line, no white space in front of it

  o _
 /|/ |   Jerrad Pierce \ | __|_ _|
 /||/   http://pthbb.org  .  | _|   |
 \||  _.-~-._.-~-._.-~-._@"  _|\_|___|___|


 -Original Message-
 From: amy [mailto:[EMAIL PROTECTED]]
 Sent: Monday, June 12, 2000 15:55
 To: [EMAIL PROTECTED]
 Subject: sendMail in cgi program
 
 
 if I run the same procedure on a separate file,
 email works, once I put the proc in the cgi
 file, I got the following error.
 
 in error_log :
 Can't find string terminator "EOF" anywhere before EOF at
 /usr/local/bin/apache/cgi-bin/lib.pl line 484.
 
 sub sendEmail {
 
 open (Sendmail, "|/usr/lib/sendmail -oi -t ")
 or die "Can't fork for sendmail: $!\n";
 
 484  print Sendmail "EOF";
 From: Bugs amy\@longsys.com
 To: amy amy\@longsys.com
 Subject: Test Create
 
 test create
 
 EOF
 close(Sendmail);
 
 }
 
 Please help.  Thank You.
 



[OT] Re: sendMail in cgi program

2000-06-12 Thread Paul

I know you've received other responses, but I'm doing a good bit of
this lately.

 sub sendEmail {
 open (Sendmail, "|/usr/lib/sendmail -oi -t ")
 or die "Can't fork for sendmail: $!\n";
 print Sendmail "EOF";
 From: Bugs amy\@longsys.com
 To: amy amy\@longsys.com
 Subject: Test Create
 test create
 EOF
 close(Sendmail);
 }

As someone mentioned on the board (ever so briefly), here-documents
like this one require that your "sentinel" string have no leading
whitespace.

e.i., you may say 
   $var=END;
  This is my variable's
  multiline text,
  complete tith tabs\t\t and extra newline\n\n, etc
END

but you *can't* say 
   $var=END;
  blah
   END

because here, END has space in front of it.
In several shells you can put tabs in front of it if you say
   print-END; # the dash says "let me use a leading tab"
   blah
tab hereEND

but I'm not sure what Perl thinks about that (I don't think it likes
it), and even in shells, it usually has to be tabs, not just
whitespace.

Note also (and please forgive me if I'm rambling =o) that the default
interpolation is double-quotish, so
   printEND;
is exactly equivalent to 
   print"END";

Both tell Perl (or the shell) to do string interpolation on the
here-doc, so you can embed variables.  On the other hand,
   print'END';
means use single-quotish behavior, and won't interpolate the vars,
which is sometimes useful.  And yes, this does mean that you can use
   print`END`;
  ls -l
  echo "Hi, Mom!\n\n"
END

...though there are probably better ways to perform such chicanery. :o/

I've found only sparse documentation for this trick (at least in basic
perl-specific docs), but use it a pretty good bit, especially in CGI's
that are going to send a lot of JavaScript (or some such) to the
client.  It's a reasonably readable way to practically switch languages
mid-script, but gives you access to some neat tricks via interpolation.
e.g., 
#~
$JS=END;
   // now writing JavaScript 
   function foo(bar) {
  // blah, $blah, $bleep{$glurf}
   }
   function bar(foo) {
  // blah, blah
   }
END
# and back to "pure" Perl ( =o)
print $query-header,
  $query-start_html(-title  = $title,
 -script = $JS,   # the above JavaScript
 -onLoad = "foo($x);",
  ), "\n"; 
#__


The biggest problem (for me, anyway) is that it throws off my
formatting to have to stick in that line with no leading whitespace.
I do it anyway a lot of the time, but if that's a problem, there's
always (well, usually, lol) qq{}.  e.g., the above example, rewritten,
would be
   $var = qq{
  blah
   };

Again, forgive me if you knew that.

As a seperate problem, your example has whitespace in front of the
"From:", "To:" and "Subject:" headers as well -- I can't say I'm an
expert on those, but does that work? Might want to test it to be sure. 
In the end, all things considered, it might work better to just build
it the hard way --
   print Sendmail "To:...\n",
  "From:...\n",
  "Subject:...\n\n", # note double newline
  # content stuff here
  "\n";

One more consideration -- I believe the specs demand a blank line after
all the headers, to signify that "the text starts *here*".

Hope that helps. =o)
And if not, sorry for rambling so! lol!

Paul

"Government should be like cooking a small fish -- don't overdo it."
   -- Lao Tzu



__
Do You Yahoo!?
Yahoo! Photos -- now, 100 FREE prints!
http://photos.yahoo.com