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

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



At 18:54 -0700 2000.08.15, Bruce Van Allen wrote:
>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";

One method I use sometimes is:

print <<HTML;
I Wuv You!
${\( $switch ? "No I Don't!" : "Yes I Do!" )}
What Fun!
HTML


That is:

  \( EXPR ) returns a reference to the value returned by EXPR

  ${   }    dereferences said value and returns it

So you can put basically any expression you want inside ${\( )}, and have
it evaluated in a string.  This is kinda nasty and hackish, but it works.
I think this suggestion is better though:

>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

-- 
Chris Nandor       |     pudge@pobox.com      |     http://pudge.net/
Andover.Net        | chris.nandor@andover.net | http://slashcode.com/

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