Literal string

Updated: 09/15/2017 by Computer Hope

A literal string may refer to any of the following:

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

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

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

However, if that same string is surrounded with double quotes instead of single quotes Perl would try to interpret the $1 as a variable unless the dollar sign is escaped as shown below.

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

The same is true if you wanted to add a variable to a string. In the example below the variable $name is assigned "Nathan" and the first print using a single quote is treated as a literal string, which means it would print "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: With both literal and interpreted strings if you need to put a quote in the string it needs to be escaped if it is the same quote used to started 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. See the "How to use FTP" for information about literal and other FTP commands.

Machine language, Programming terms, Variable