[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] wwwboard.htm and sub routines



At 5:02 PM 8/15/00, Tim Reynolds wrote:
>Hi,
>
>I am using Matt's wwwboard script (scriptarchive.com) and I would 
>like to create a different sub return_html routine with the script.
>
>Instead of printing out each line of HTML code - which is how the 
>original script is done - I did this:
>
>print "Content-type: text/html\n\n";
>print <<"HTML code";
>
>and then placed all of my HTML code for the reponse page here
>
>HTML code
>}
>
>However by doing it this way I am unable to process part of Matt's 
>sub routine which is:
>
>if ($message_url) {
>print "Link: $message_url_title
>\n";
>}
>if ($message_img) {
>print "Image:
>\n";
>}
>
>With my method the HTML actual prints out the perl code onto the 
>page. I would rather not code every line of HTML because the page is 
>rather long - does anybody
>know how I can include the above conditionals and still use
>
>print <<"HTML code";
>


[Further discussion on this should be posted to the MacPerl-CGI list.]

1. Break the "heredoc" into two so you can insert your conditional processing.

print <<"HTML 1";
first stuff
to print
HTML 1

if ($x = $y) {
	print "dit dot"
}

print <<"HTML 2";
later stuff
to
print
HTML 2

2. Or, do your conditional process first; put the outcome -- no 
matter what, even '' -- into a variable, insert that variable into 
the long batch of output enclosed in your heredoc, and make sure you 
get double-quote-style interpolation (by either using double quotes 
as you did above, or no quotes at all.

$out = '';
if ($x = $y) {
   $out = "dit dot"
}

print <<THIS;  # <-- No quotes => double-quote interpolation
stuff to
print
$out
byebye
THIS

3. In either case, make sure you have no extra whitespace on the same 
line before or after the closing string delimiter (i.e., the 'HTML 1' 
or the 'THIS').

Further gratuitous advice:

4. One note: In the long run it's way preferable to have your HTML, 
even containing Perl variables or references, in a separate file, 
rather than right in your script. Ease of modification/maintenance, 
less danger of editing errors, code more easily re-used, etc.

5. As is mentioned periodically on this list, MW's scripts are rather 
notorious for problems. Search for "Matt Wright" (or "Matt Wrong") in 
the archives. You might want to take a look at CGI.pm. Saves much 
work, great opportunities to learn more Perl, excellent book and 
online documentation, continually maintained by a master programmer 
with lots of feedback from professional coders.

HTH

1;



-- 

- Bruce

__Bruce_Van_Allen___bva@cruzio.com__Santa_Cruz_CA__

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org