Reputation: 1
I am working on an assignment where I must use an HTML font tag to change the font color of an perl output statement. I've followed the direction in the assignment, and this is what the code looks like:
print $FILE2 "<font color = 'red'> var1 </font>";
$FILE2 is the filehandle for the file I am writing to. Var1, Var1 is a test variables. However, there is no color change and the syntax above is printed exactly like that to the screen. I'm not really sure what I am doing, wrong, can somebody please help me? I have not included any headers other than strict and warnings.
Upvotes: 0
Views: 627
Reputation: 9231
Variables in Perl are always indicated by sigils. In this case you are dealing with scalars (single value container), and the sigil for a scalar variable is $
. This sigil is also what allows it to be interpolated (replaced with its value) in a double-quoted string like you have. See perldata for more info.
As a side note, interpolating variables directly into HTML can be dangerous because they can contain HTML tags. If you want to avoid the possibility of the input adding tags of its own, pass the input through an HTML-escaper like encode_entities from HTML::Entities or xml_escape from Mojo::Util first. The usual way to construct HTML like this is with templates, and templating modules often provide such functionality built in.
Upvotes: 1