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

when i need to output html is it possible to do the following for example an option box.
print" <TD width=60>Team 1 </TD>" print"<TD width=200>" print"<P align=center><SELECT name=Team1 size=1>" print"<OPTION selected value=101>$variable</OPTION>" print"<OPTION value=103>something</OPTION>" print"<OPTION value=103>somethingelse</OPTION>"
or to get an image to put in a table when a certain variable is selected where the variable name is thename of the image in the location below.
Print”<td width="495"><img border="0" src="images/ $variable.jpg" widt +h="430" height="80"></td>” can u do this???

Replies are listed 'Best First'.
Re: cgi output.
by Masem (Monsignor) on Mar 16, 2001 at 02:15 UTC
    You can certainly do that; you might find some of the functions in CGI.pm to be easier to use as to avoid 'polluting' your code with direct HTML, or you could look at the templating modules (Text::Template, HTML::Template, for example) to move HTML out from perl and into supplimentary files.

    Just don't forget to end your perl statements above with semicolons (';'). Also, if you use quotes for things like the img src tag, you'll need to escape them (eg, enter it as "src=\"something.jpg\"").


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: cgi output.
by chromatic (Archbishop) on Mar 16, 2001 at 02:14 UTC
    Yes, you can. Feel free to try it.

    Note that you might have to be slightly explicit about the variable name, in case you want to interpolate the variable into a string with lots of other text. If you have a variable called $filename and you want to add numbers to the end, you will have to say:

    print "${filename}1.jpg";

    and so forth.

Re: cgi output.
by andye (Curate) on Mar 16, 2001 at 17:49 UTC
    As well as here documents, qq{ } is well useful for this.

    print qq{ this HTML's "full" of <P class="funky"> 'unescaped quotes' and interpolated $vars</P> <IMG SRC="$img"> };

    andy.

Re: cgi output.
by faerloche (Sexton) on Mar 16, 2001 at 08:09 UTC
    I'd write something like that with a here doc.. HTML can get really ugly if you have to \" all the quotes :-)

    print <<EOF;

    <TD width=200>
    <P align=center>
    <SELECT name=Team1 size=1>
    <OPTION selected value=101>$variable</OPTION>
    <OPTION value=103>something</OPTION>
    <OPTION value=103>somethingelse</OPTION>
    EOF