Literal string

Updated: 08/02/2020 by Computer Hope

A literal string may refer to any of the following:

1. Alternatively referred to as literal(s), a literal string is a series of characters enclosed in double or single quotes, depending on the programming language or command line. A program does not interpret characters in a literal string until it encounters the next double or single quote.

For example, in Perl using the command below, it would print "Hello World! Here is a $1."

print 'Hello World! Here is a $1';

However, surrounding the string with double quotes instead of single quotes causes Perl to try interpreting the $1 as a variable. Escaping the dollar sign results in Perl treating the dollar sign as a literal character, as shown below.

print "Hello World! Here is a \$1";

The same is true if you want to add a variable to a string. In the following example, the variable $name is assigned "Nathan", and the first print using a single quote is treated as a literal string, which means it prints "Hello $name". However, the second print with double quotes is an interpreted string and would print "Hello Nathan".

use strict;
my $name = "Nathan";
print 'Hello $name';
print "Hello $name";
Tip

For literal and interpreted strings, if you need to insert a quote, it must be escaped if it's the same quote used to start the string.

2. When connected to an FTP session, the literal command sends a literal string to the connected computer and expects a one-line response.

Machine language, Programming terms, Variable