Node:Single-quoted Strings, Next:, Previous:Strings, Up:Strings



Single-quoted Strings

String literals can be represented in primarily three ways in Perl. The first way is in single quotes. Single quotes can be used to make sure that nearly all special characters that might be interpreted differently are taken at "face value". If that concept is confusing to you, just think about single quoted strings as being, for the most part, "what you see is what you get". Consider the following single-quoted string:

     'i\o';  # The string 'i\o'
     

This represents a string consisting of the character i, followed by \, followed by o. However, it is probably easier just to think of the string as i\o. Some other languages require you think of strings not as single chunks of data, but as some aggregation of a set of characters. Perl does not work this way. A string is a simple, single unit that can be as long as you would like.1

Note in our example above that 'i\o' is an expression. Like all expressions, it evaluates to something. In this case, it evaluates to the string value, i\o. Note that we made the expression 'i\o' into a statement, by putting a semi-colon at the end ('i\o';). This particular statement does not actually perform any action in Perl, but it is still a valid Perl statement nonetheless.


Footnotes

  1. Actually, it cannot be longer than your computer has virtual memory, but that is rarely a problem.