You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Paul <yd...@yahoo.com> on 2000/06/13 00:30:21 UTC

[OT] Re: sendMail in cgi program

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 <am...@longsys.com>
>         To: amy <am...@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 here>END

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
   print<<END;
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

Re: [OT] Contract Language for free software

Posted by Ed Phillips <ed...@homewarehouse.com>.
Please excuse the horrible formatting,
The version below should be more readable.


Ed Phillips wrote:

> Hi All,
>
> This is very OT, but is related to mod_perl.  I have a contract as yet
> unsigned
> with a Web Company to possibly rewrite their horrible perl 4 era CGI apps
> as nice  clean mostly OO mod_perl apps. It's a simple job, rather generic.
>
> I usually license my code with the Artistic License, so this is not a
> Licensing
> question, exactly. In the contract, they have sent me, they have a
> paragraph
> that signs the rights to all inventions over to them.
>
> From my perspective, what little invention there might be in these apps,
> is drawn directly from freely available documentation and advice, and
> the apps will of course rely heavily on CPAN modules, as well as
> things I've written before. So, what I'm looking
> for is advice or a paragraph that establishes that the greater part of
> invention
> is already public, that these programs use free software, and that
> non-specific
> to their business inventions, if any should be returned to the community,
> etc.
>
> I'm not a lawyer. :-) In the past, I've just ignored such paragraphs and
> I've
> lowered the boom in a banner at the top of my code.  But, I'd like to put
> something
> in any contract that I sign and these people have no idea how to deal with
> free software.
> They want me to sign an NDA now that I've seen their hideous spaghetti,
> which is
> of course full of copyright notices.  I told them that if anyone stole
> this code, they would
> need their head checked!
>
> If someone has crafted any pro free software contracts that cover
> invention and
> they would like to share, I'd be grateful.
>
> Cheers,
>
> Ed


[OT] Contract Language for free software

Posted by Ed Phillips <ed...@homewarehouse.com>.
Hi All,

This is very OT, but is related to mod_perl.  I have a contract as yet
unsigned
with a Web Company to possibly rewrite their horrible perl 4 era CGI
apps
as nice  clean mostly OO mod_perl apps. It's a simple job, rather
generic.

I usually license my code with the Artistic License, so this is not a
Licensing
question, exactly. In the contract, they have sent me, they have a
paragraph
that signs the rights to all inventions over to them.

Re: [OT] Re: sendMail in cgi program

Posted by Ian Kallen <sp...@salon.com>.
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 here>END

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