You might want to rethink using CGI.pm for this, although it's not difficult. Just because it provides the methods doesn't mean you have to use them. That aside, CGI.pm can create any kind of HTML tag you want : if you use the OO interface, print $query->foo("hah!"); will output

<foo>hah!</foo>

To set attributes of such a tag, the first argument you give to the method or function must be a hash reference or anonymous hash that associates each attribute with its associated value. So, in this case,

print font( { color => "red" }, "This text is in red");

Will produce the following HTML :

<font color="red">This text is in red</font>

FWIW, though, being an up-to-date, let's-follow-w3c-recommendations kinda guy, I'd use

span({style=>"color:red"}, "This text is in red");

or style sheets to make text red.

Incidentally, your problem could be solved fairly simply: just embed the font tag in the text you're outputting, like so:

print p("I like <font color='red'>red</font> text"); # or print p("I like ", font({color=>"red"}, "red"), " text");

Or use here documents :

print <<END_OF_TEXT; <p>I like <font color="red">red</font> text.</p> END_OF_TEXT

Keep in mind that you *don't need* to use CGI.pm to generate all your HTML.

HTH.

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

In reply to Re: How do I create font tags with cgi.pm? by arturo
in thread How do I create font tags with cgi.pm? by apprentice

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.