Another thing to keep in mind is that you must use a backslash to print a $ symbol. Without it, Perl will try to interpret it as a variable. Behold:
print "I have $15.00 in my pocket boyee!";
If you try to run that program you will get an odd result:
I have .00 in my pocket boyee!
Very odd indeed. Since we aren't trying to print a variable, the proper way to write this code would be:
print "I have \$15.00 in my pocket boyee!";
Which would give us the correct print out of:
I have $15.00 in my pocket boyee!
Similarly, you cannot print out an @ symbol either. The following will not work:
print "My email address is email@example.com.";
If you used this code it would print:
My email address is james.com.
To fix this, we again use our good old buddy the backslash:
print "My email address is james\@james.com.";
Which prints out:
My email address is firstname.lastname@example.org .
print "\n\nPlease find my favorite color and number below:\n\n";
print "\tMy favorite color:\t\t\t$color\n";
print "\tMy favorite number is:\t\t\t$number\n\n";
This will print out our text and variables so that they appear like this on the user's screen:
Please find my favorite color and number below"
My favorite color: black
My favorite number is: eight
Well that's all the time we have for this exciting episode. Join us next time when we continue this intriguing, gut wrenching discussion on Perl text manipulation. I look forward to seeing you.
blog comments powered by Disqus