In the last article, you learned how to install Perl. It wouldn't make a lot of sense to install it on your computer if you never did anything with it, now would it? In this article, you'll take your first steps to becoming part of a wild and crazy breed -- a Perl programmer.
In the above example we worked with a string, or a group of characters. We encased it in single quotes ('), which lets the program know where the string ends and begins. Which is fine and dandy. But what if you come across a contraction? If you try the following code you will get strange results:
#!/usr/local/bin/perl
$my_sentence = 'I simply can't do it!';
print "$my_sentencen";
Because there is a single quote(') in the contraction can't, the program sees the word can as the end of the string, instead of the word it with an exclamation mark, as we originally intended. To fix this, you escape the quote with the backslash() key.
#!/usr/local/bin/perl
$my_sentence = 'I simply can't do it!';
print "$my_sentencen";
To use special characters like the n or to print a variable, we use the double quotes("). Consider the following:
#!/usr/local/bin/perl
$my_sentence = 'I simply can't do it!';
print "$my_sentencen";
print '$my_sentencen';
In the above code, the following would print out:
I simply can't do it!
$my_sentencen
See? You need the double quotes for those special keys, otherwise they will be seen as a normal string of text.