in reply to HTML embedded in perl

With back-slashing you need to \ the " chars within the string like so (BTW generally you don't need STDOUT as this is the default):

print STDOUT "<FONT COLOR=\"red\">$data</FONT>";

The \ lets Perl know you mean a literal " not a " as in the end of the string you are printing. Typically you avoid this problem using heredocs or the qq operator

# to print a bunch of HTML using a heredoc I would do: print <<HTML; <html> <head> <title> $title </title> </head> <body> <P><FONT COLOR="red">$data</FONT> <P>$some_content <-- continue --> </body> </html> HTML # or you can do this with qq (non interpolated text must not contain ! + char) print qq! <html> <head> <title> $title </title> </head> <body> <P><FONT COLOR="red">$data</FONT> <P>$some_content <-- continue --> </body> </html> !;

"red" is fine but if you want to use hex it is #RRGGBB where #FF0000 is red and #0000FF is blue.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: HTML embedded in perl
by mjemmeson (Monk) on Dec 17, 2002 at 10:00 UTC
    "# or you can do this with qq (non interpolated text must not contain !)"

    You've missed the exclamation marks from your HTML comments start tags.

    For HTML I often find it better to use a character other than an exclamation mark to begin and end the qq string, to avoid having to frequently escape them. (Characters can be anything non-alphanumeric and non-whitespace).

    cheers,
    michael

      ;-)

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: HTML embedded in perl
by PetaMem (Priest) on Dec 18, 2002 at 08:41 UTC
    Excuse me, but this won't work. $data and $some_content won't get interpolated. You have to use << "HTML" instead.

    update: forget this, look at the replies to this node, they're right. And the ancestor node is right too. The only node not being right is this one. :-}

    Bye
     PetaMem

      Sorry, but you are incorrect. qq IS what you use to double quote text and have variables interpolated. q will single quote and not interpolate.

      #!/usr/bin/perl -w

      use strict;
      my $text = "INSERTED TEXT";
      print qq! There is tome $text here \n!; # THIS INTERPOLATES
      print q! There is some $text here \n!; # THIS DOESN'T

      Actually interpolated context is the default. You don't need the rabbit ears.

      $why_dont_you_check_your_facts_before_you_embarass_yourself = 'Oops!'; print <<THIS; I would have to say: $why_dont_you_check_your_facts_before_you_embarass_yourself THIS

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print