Mega Code Archive

 
Categories / Perl / String
 

The difference between single and double quotes

Perl uses single (') or double (") quotes to indicate the start and end of text strings.  Perl provides less interpretation of what's in a single-quoted string.  In a single-quoted string: \n is two characters, a backslash and an n. \' and \\ are the only allowed backslash escapes. The value of variables are not substituted, so that '$var', for example, is simply a dollar sign and the letters v-a-r. You can have a real newline in the text, such as the following: 'line 1  line 2'  Double quotes You can use the full set of backslash escapes, such as \t for a tab and \n for a newline. You can substitute the value of variables, such as $var. You can also embed a newline in the string, as you can for single-quoted strings: "line 1  line 2"