Perl has always been known for its text processing and manipulation abilities. This article examines the Perl string handling API in greater detail, explaining how you can use Perl's string functions to (among other things) print and format strings, split and join string values, alter string case, and perform regular expression searches.
The << symbol indicates to Perl that what comes next is a multi-line block of text, and should be printed as is right up to the marker "EOF". This comes in very handy when you need to output a chunk of HTML code, or any other multi-line string.
Strings can be concatenated with the string concatenation operator, represented by a period(.)
# set up some string variables
$a = "the cow ";
$b = "jumped over ";
$c = "the moon ";
# combine them using the concatenation operator
# this returns "the cow jumped over the moon"
$statement = $a . $b . $c;
# and this returns "the moon jumped over the cow"
$statement = $c . $b . $a;
Note that if your string contains quotes, carriage returns or backslashes, it's necessary to escape these special characters with a backslash.
# will cause an error due to mismatched quotes
$film = 'America's Sweethearts';
# will be fine
$film = 'America\'s Sweethearts';
The print() function is used to output a string or string variable.
print "Last Tango In Paris";
# string variable
$film = "Last Tango In Paris";
But if you thought that all you can do is concatenate and print strings, think again - you can also repeat strings with the repetition operator, represented by the character x.
# set a string variable
$insult = "Loser!\n";
# repeat it
print($insult x 7);