There are lots of way to express yourself, but with programming languages the simplest way to do that is usually text. This tutorial will walk you through ways to make text work for you in Perl. It's the first of a three-part series, and since (as usual) we have a lot of ground to cover, let's get started.
As you will no doubt recall, we discussed strings on a surface sort of a level a while back. Here, in this tutorial we will go more in depth. We will start off with the basics, so if you are a pro, feel free to skip over that section. If not, or if you want a refresher, sit back, take a sip of that wine in the box over there on the table, and as the great Marvin Gaye once said, let's get it on.
Basic Printing
We learned before how to write basic text to the screen using the print command. As a refresher, here it is again:
#!/usr/bin/perl
print "My name is James Payne. ";
print "I am the world's fattest man.";
print "My weight is equivalent to that of 17 suns. ";
print "Or 17 of Oprah's sons. You pick. ";
print 102;
print " 102 ";
print 10+2;
print " 10+2 "
When you run this program, you get the following result:
My name is James Payne. I am the world's fattest man. My weight is equivalent to that of 17 suns. Or 17 of Oprah's sons. You pick. 102 102 12 10+2
As you can see, all of our text is printed on the same line. If I had not put a space at the end of each sentence, it would all be bunched up as well. To fix this issue we can use what are known as special characters.