Home / Perl / Archive by category 'Perl string manipulation'

Perl string manipulation

Defining strings and newlines in perl

The declaration below indicates two different characters, \ and an n.

$string = '\n';

Declaring literal with single quotes

$string = 'Jon \'Main\' Deva';

Double quotes interpolate variables and expand a lot of backslashed shortcuts: \n becomes a newline, \033 becomes the character with octal value 33, \cJ becomes a Ctrl-J, and so on.

$string = "\n";                     # a "newline" character
$string = "Jon \"Main\" Deva";  # literal double quotes